objective-ciosdatabasecocoa-touchdata-storage

Most efficient way to save data on iOS Apps


I am creating an App containing multiple UITableViewControllers. So far I have made all of them connect to my different JSONGetStuff.php files, then getting the data from my database with a JSON encode. This works great. Most tables have cells containing both text and image. Now that I have four tableViews containing different data, I feel like saving the data rather than loading it each time. Now I make the app access the JSON.php files on ViewDidLoad, and store the data in an NSArray, and then parse them through NSDictionary to get ObjectForKey:@""; This data is a normal table from a SQL server, like "Name" "Adress" "ImageName" etc.

I have realized that I'm not going to update the database too often, most likely once or twice a month, maybe even less. So I decided I want to store the information in the app insted. Not in the way that I have to release an update everytime I change the database, but like saving until updated.

I figured I should have an integer named "Version" in my app, being = 1; on release. Then, when the app is launched, I want to make the app go to www.mywebsite.com/version.php, and check if the variable echoed out is the same as "Version". Whenever I change my database, I can change this integer ++. When the app launches, and checks the version, and it is wrong locally, then I want it to download the whole load, and overwrite the current data stored on the iPhone.

I have no clue where to begin. I use JSON because it's bad to connect directly to a database, but since the my data is database-data, could I create a local database and use that information instead of an Array? I read somewhere that maybe .plist was better for strings, and my whole database is just strings (varchar x).

Where do I save the initial data? How do I parse my database-data over there using i.e JSON? How do I overwrite that data when the time has come? And where do I begin? Should I read up on .plist, NSData, NSCoding or NSFileManager?


Solution

  • Try to consider having the data persistent in a core data database. Core data is a persistent framework to handle databases. Core data handles a lot of stuff for you (relationships, memory, etc), and plays very well with tables (using NSFetchedResultsController).

    https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreData/index.html

    It will all depend on the amount of data, of course, but you can start taking a look at the linked document.