Approach for small database - iOS

人盡茶涼 提交于 2019-12-11 12:46:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!