问题
i am building an app that requires me to store a number of things.
I have a data object consisting of 4 to 5 BOOL variables, there could be 800 - 1000 such objects which i will need to persist.
Am confused how should i program this, should i go for an sql database or Core data, since NSUserdefaults is not an option obviously.
回答1:
You can easily store them in a plist as @adobels suggested. Your Class would store the BOOLs in a NSNumber and your class implements NSCoding:
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:member1ToStore forKey:@"yourFirstBoolKey"];
}
- (id)initWithCoder:(NSCoder *)coder ...
If all the instances of your class are in an NSArray (or similar Cocoa Collection) you then simply archive and unarchive to a file like
[NSKeyedArchiver archiveRootObject:yourCollectionOfClasses toFile:archivePath]
[NSKeyedUnarchiver unarchiveObjectWithFile:[[self archiveURL] path]];
See documentation at apple developer and this fine answer
回答2:
1000 object can be also stored in plist. Generate a .plist file with 1000 of objects of your type. Then check a performance within your app. If it's ok then your app will simpler to write.
来源:https://stackoverflow.com/questions/35377705/approach-for-small-database-ios