Closed sagits closed 8 years ago
EVObject supports NSCoding. You could directly save an object to the NSUserDefaults. you do not have to convert it back and forward to json.
If your data is more than a couple of K, I think it's better to save it to disk instead. You could use NSCoding for that or just the saveToTemp or saveToDocuments function on the EVObject itself. If you have an array of object, then you only have to call: NSKeyedArchiver.archiveRootObject(data, toFile: filePath)
Thank you for answering. Can i save a list o EVObjects directly too? I'll try this approach (saving in files) and do some benchmarking.
Yes you can. Arrays also support NSCoding. So you can write an array with something like:
NSKeyedArchiver.archiveRootObject(data, toFile: filePath)
I have used that in EVCloudKitDao. See this code as a sample:
https://github.com/evermeer/EVCloudKitDao/blob/0ee2bb09e407d5cf72fd6b1339029ec6b018c686/AppMessage/AppMessage/CloudKit/EVCloudKitDao.swift#L504-L504
Hi evermeer, i just want to expose the approach im using to save json for local usage. My app basically loads data from the api on the first time and on the next it check if theres local data instead of downloading it again, the user can use a pull to reflesh to force the redownload.
Im using NSUserDefaults for saving a json array and using EVReflection to parse it when retrieving. What do you think about this approach? Heres the code: