1

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.

mahal tertin
  • 3,239
  • 24
  • 41
Pulkit Sharma
  • 545
  • 1
  • 6
  • 19
  • I may not able to answer your question but I surely add some links which may help you at some level. You can check [this](http://stackoverflow.com/questions/1318467/use-coredata-or-sqlite-on-iphone) and [this](http://www.drdobbs.com/mobile/ios-data-storage-core-data-vs-sqlite/240168843). – Hemang Feb 13 '16 at 10:17
  • 800 Objects with each 4 Bool results in exactly 400 Bytes of Data, 1000 Objects with 5 Bool still is less than 1 Kilobyte. You're way beyond the capabilities of databases and core data . – mahal tertin Feb 13 '16 at 12:56

2 Answers2

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

Community
  • 1
  • 1
mahal tertin
  • 3,239
  • 24
  • 41
  • The boolean variables will be editable too, that too very often. So is your aproach a good practice to use for my requirement ? – Pulkit Sharma Feb 13 '16 at 14:40
  • save it each time the user makes an edit. if this happens more than once a second: do it only once a second. and measure how long it takes to save. – mahal tertin Feb 13 '16 at 14:49
  • @PulkitSharma if this answer helped you, i would kindly ask you to accept it using the green checkmark on the left hand side. Or comment on how I could improve the answer. – mahal tertin Feb 16 '16 at 09:16
0

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.

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93