Saving data to disk in iOS

My app was rejected for the following reason:

App Review
1.0 Binary Rejected August 5, 2015
2.23 Details On launch and content download, your app stores 9.51 MB on the user iCloud, which does not comply with the iOS Data Storage

      

It is my understanding (correct me if I am wrong) because I am saving too much on NSUserDefaults

( saving nothing else).

So here's my question: is there a quick and easy way to save data locally (similar to NSUserDefaults

, but not end up saving "iCloud user" instead of using it CoreData

?

+3


source to share


1 answer


Yes, there is a way. You can store your data with NSKeyedArchiver

and NSKeyedUnarchiver

. NSKeyedArchiver

used to save your data. Example:

[NSKeyedArchiver archiveRootObject:counters toFile:filePath];

      

The extension filePath

should be .plist

; counters

in this case is an array.



NSKeyedUnarchiver

used to load your data. Example:

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
    counters = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
}

      

If you want to keep your own class, you need to implement the protocol NSCoding

.

+2


source







All Articles