Im wondering how I go about serializing the entire core database on an iOS app to JSON so I can back it up in the cloud. Than when the user wants to restore how to go about taking the JSON string back and generating an entire core database from that?
Is it possible? Any advice?
Thanks
Sure. You can easily use
NSJSONSerializationto serialize/deserialize objects to/from JSON, andNSURLRequest/Connectionto upload or download JSON.AFNetworkingis a popular networking framework that has JSON serialization/deserialization built in. I have not used it yet so I cannot vouch for it personally, but it looks quite functional.NSManagedObject(the Core Data base object) has anNSEntityDescriptionassociated with it, which has the method- (NSDictionary *)attributesByName, which should make it easy to write serialization/deserialization methods without having to write explicit code for every class and attribute.I find Core Data to be heavy and complex for most of my needs and typically write local storage and serialization/deserialization using the
NSCodingprotocol. You might look into that as well for future projects.