1726

Approach for small database - iOS

Question:

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.

Answer1:

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 <a href="https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson10.html" rel="nofollow">documentation at apple developer</a> and <a href="https://stackoverflow.com/questions/8727508/ios-persistent-storage-strategy?answertab=active#tab-top" rel="nofollow">this fine answer</a>

Answer2:

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.

Recommend

  • Back and forth movement using Rigidbody2D movePosition
  • Pandas: drop row if more than one of multiple columns is zero
  • Testing if a list of integer is odd or even
  • Is Cocoa's NSMutableArray sparse?
  • Deleting a row in tableview without deleting Core Data Entity
  • How to show bar values on CorePlot -Stacked bar chart
  • Add Action To Apple TV Remote Play/Pause Button
  • How to keep the user logged in or check if the user is logged in or not in Shopify?
  • didDiscoverServices is not being called after a BLE connection
  • How to check repetition of numbers in an array?
  • Programmatically rotate iOS app upside down using objective-c
  • Push notification applicationIconBadgeNumber is not update in ios7
  • Changing pitch in an iOS audio player—like Alvin and the Chipmunks
  • iPhone4 SecItemCopyMatching returns -25300 after reboot
  • Localization of CFBundleDisplayName doesn't work whatever I try
  • Sending array data from one view controller to another
  • cant create handler inside thread that has not called looper.prepare
  • iPhone — MKReverseGeocoder.adminstrativeArea — getting state abbreviation
  • How can integers (keys & values) be added and retrieved from a NSDictionary
  • iOS custom UTI in UIDocumentPickerViewController initWithDocumentTypes
  • Core Data To-Many Relationship Creating Duplicates When Adding Object to Parent Entity
  • Jquery UI Sortable, move item automatically
  • c++ using primitive types as a base class
  • CFBundleDevelopmentRegion not works as expected
  • Criterion causing memory consumption to explode, no CAFs in sight
  • apply a javascript function to draggable copy
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • How do I access an unhandled exception in an MVC Error view?
  • How to define and use opencv mat of user type
  • MailKit: The IMAP server replied to the 'EXAMINE' command with a 'BAD' response
  • Google Custom Search with transparent background
  • vba code to select only visible cells in specific column except heading
  • log4net write single file for each call to log.info
  • Java static initializers and reflection
  • unknown Exception android
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app
  • To Get the radio button value in ruby on rails