Reputation: 149
In my iPhone application I get json data from a remote server, parse it using the Json Framework and present it in a UIview. Also want to be able to give the user the option to store the data on the device so that it can also be viewed offline. I was wondering if storing the json data directly is a better or worse choice than making an object and then saving it using NSCoding + NSKeyedArchiver. I assume that the advantage of storing a json string as it is, is that it takes less space on disc than an archived object while, on the other hand, by storing archived objects you don't have to parse the stored data every time thus using less memory.
Is there a best overall choice? Are there any best practices on that matter? The json files size is approximately 8KB.
Upvotes: 5
Views: 3918
Reputation: 1265
I use a different approach. Once the JSON data is parsed in my app, its stored in a NSDictionary. I persist that as a .plist file.
[myDictionary writeToFile:[self saveFilePath] atomically:YES];
To Load:
NSMutableDictionary *wholeDictionary = [NSDictionary dictionaryWithContentsOfFile:[self saveFilePath]];
That's it!
Upvotes: 6