macoscocoacore-datanspersistentdocument

Is it bad to use NSPersistentDocument with an alternate save format?


I'm thinking of making a Core Data-based document-centric application, but I want the saved file format to be my own proprietary bundle of XML, images and other stuff.

My plan is to use a subclass of NSPersistentDocument that serializes back and forth between my file format and Core Data when receiving calls like -writeToURL, -readFromURL, and so on.

Is this an anti-pattern? I've started experimenting with it and it seems like it would work, but I don't see much documentation/discussion about this approach, which gives me pause.


Solution

  • Use a custom atomic store type. You only need to be a valid store type that handles what Core asks and everything else should "just work". Your custom store type can then act as the translation layer between Core Data and your own format.