Advise where to store data for iOS app

I created an application using ionic and cordova and now I want to redo it on iOS. I am working with iOS for the first time and I cannot figure out how to store data. For example: I have a form where the user has to enter some data, but the inputs are not in the same view, there must be multiple views. I used to create an empty array and just put everything in step by step, but now I cannot use the same view controller on multiple views. Tried to do it with core data, but core data can't store arrays. My object will look something like this:

var sampleArray = (
duration: 13,
dayOfTheWeek: Thursday,
personList: [
  (name: Rocky,
   age: 26),
  (name: Ralph,
   age:23)
  ]
)

      

The question arises: how could I create an input form that would be in several views, and where should I store the data, and later I can store all the data in the main data?

+3


source to share


2 answers


As the first comment says, your question is pretty big. When you say "one shape per view" I think of it as "one shape per view". Keep It Simple S ...;) (Except when you are using a page control for your form.)

Basically, you have three ways to store data:



  • NSUserDefaults: Store data in a dictionary for later use.
  • File: Save the data to a file (why not .csv?)
  • CoreData: You can save arrays as binary data in Core Data li>

There are many tutorials on these topics. www.raywenderlich.com is a good site to start ...

+2


source


You can work with persistent data in several ways in iOS.

Custom default

It is a tool that is used to store small amounts of information such as user preferences, settings, etc. Don't use it for data that will scale when using apps (like notes in a notepad app). The Documentation will answer all your questions about custom defaults.

Database

You have Master Data as a turnkey solution that is built on top SQLite

and takes a while to find out, but in my experience it is well worth the effort. You can use a pure SQLite

or a different type of database, but this requires more code and possibly custom frameworks.

Text files



You can use arbitrary files XML

, JSON

or CSV

to store your data. The tool is rich (like NSXMLParser or SwifyJSON just for name two) and if you look at Github you will find what you need. You can also use assembly in combination with NSCoder and NSKeyArchiver / NSKeyUnarchiver which are easy to understand.

Binary files

Finally, for local storage, you can use binaries, i.e. images. This topic is too complex, but I want to share an example of Open Bitmap File Format . It is used to store information for drawing applications (such as GIMP) and internally, it is basically an XML file and many images compressed in a zip called an .ora file. Creating your own specification for the hybrid format isn't that hard.

Network repository

To watch out for other methods, you can use the remote database API to store data off-device, but of course you need your own host and some backend skills.

I hope I haven't missed something important. I just wanted to summarize this knowledge in one place for future reference.

+1


source







All Articles