Advise where to store data for iOS app

后端 未结 2 648
小鲜肉
小鲜肉 2021-01-20 18:34

I have created an app using ionic and cordova and now I want to remake it on iOS. I am working with iOS for the first time, and I cannot figure out how to store data. For ex

相关标签:
2条回答
  • 2021-01-20 18:44

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

    User Default

    This is a tool that is used to store small amounts of information like user settings, preferences etc. Don't use it for data that will scale with application usage (e.g. like notes in notepad app). Documentation will answer all your questions about User Defaults.

    Database

    You have Core Data as an out of the box solution which is build on top of the SQLite and takes some time to learn, but from my experience it's worth the effort. You are free to use pure SQLite or other database type, but it requires more code and probably custom frameworks.

    Text files

    You can use arbitrary XML, JSON or CSV files to store your data. Tooling is rich (e.g. NSXMLParser or SwifyJSON just to name two) and if you look on Github, you will find what you need. You can also use build in combination of NSCoder and NSKeyArchiver / NSKeyUnarchiver which are easy to grasp.

    Binary files

    Finally, for a local storage you can use binary files i.e. images. This is too advanced topic to cover here, but I want to share an example of Open Raster file format. It is used to save informations for drawing apps (eq. GIMP) and inside, it is basically an XML file and a bunch of images compressed to zip and named as .ora file. Creating your own specification for a hybrid format is not that hard.

    Network repository

    Just to not overlook other methods, you can use remote database API to store data outside of the device, but of course you need your own host and some backend skills.

    I hope I didn't miss something important. I just wanted to sum up this knowledge in one place for future reference.

    0 讨论(0)
  • 2021-01-20 18:55

    As the first comment says, your question is quite large. When you say 'one form on several view', I consider it as 'one form per view'. Keep It Simple S... ;) (Except if you use page control for your form.)

    Basically, you have three ways to store data :

    • NSUserDefaults : Store data in Dictionary for later use
    • File : Save data to a File (why not .csv like ?)
    • CoreData : You can persist arrays as binary data in Core Data

    There are numerous tutorials on these topics. www.raywenderlich.com site is a good one to begin...

    0 讨论(0)
提交回复
热议问题