Reputation: 10738
Can someone be so kind and explain the options to read and write information in iOS? What I’m looking for is not explanation on how to read and write simply the options available when saving in iOS.
The main reason for this question is because I’m currently practicing with a small app I created, the app does some calculations and I would like to be able to save the result locally for later use.
What are the options when saving a simple NSString locally in iOS? Is this even possible?
If the above is possible, where are these local files saved?
How much can you save locally before you need a database?
What classes/methods should I be looking into (the only one I found so far is NSData)?
Again what I’m looking for with this question is understand what the options are when reading and writing information in iOS.
Thanks a lot.
Upvotes: 0
Views: 103
Reputation: 3494
There are several options for saving data in iOS application:
NSUserDefaults, recommended for primitive types(string, bool, etc) or NSDictionary
NSFileManager, - for reading, writing, copying, moving, renaming files in your app
NSCoding, - for storing objects that comply to the nscoding protocol
CoreData, - and of course core data framework for complex data models
If the above is possible, where are these local files saved?
NSUserDefaults is a class but i think it saves in a plist file in the app bundle(i might be wrong about this one);
NSFileManager - saves the files on disc in one of it's standard Directories like the Document directory
NSCoding - on disc similar to the NSFileManager,
CoreData saves it in a sqllite database.
How much can you save locally before you need a database?
Depends on the device but since you don't plan to save 1 G files on the device i think you should think in therms of architecture - how complex is the data model and for what pourpes will you use it
What classes/methods should I be looking into (the only one I found so far is NSData)? NSData hase a few methods about how to convert it into a file and save it to disc, these are convenient methods, but for the raw file manipulation look at the links above.
Upvotes: 1