Reputation: 1484
i need to store some objects from table. It will be no more than 100 objects. Is it good way to store it like array in NSUserDefaults? Or there is any better way?
Upvotes: 0
Views: 290
Reputation: 38259
Store all custom data in NSDictionary or NSArray.
Now save dictionary or array with custom data in document directory follow this link
Upvotes: 0
Reputation: 1658
no Storing data on NSUserDefaults is not good, because it can cause a serious hack.
instead of it you can use AppDelegate to store data globally.
Upvotes: -2
Reputation: 25318
The better way would be to serialize it as a binary blob on disk using NSArray
s writeToFile:atomically:
or writeToURL:atomically:
. NSUserDefaults
aren't stored as binary and thus need extra parsing time upon loading, and extra time to write out to disk. NSUserDefaults
is also not designed to hold large amounts of data but for a small set of settings data.
Upvotes: 2
Reputation: 130222
Although you can store this is NSUserDefaults
using [[NSUserDefaults standardUserDefaults] arrayForKey:@"key"];
you probably shouldn't. Defaults was designed to store VERY small ammounts of data, like a users preferences (thus the name). If you wish to store more data than this, then you may want to look into .plists
, NSDocumentDirectory
, Core-Data
, or SQLite
databases.
Upvotes: 3