Search code examples
macoscocoacore-datansdocument

OS X Data file editor saving to XML: Document based or not?


So I'm trying to make a data editor for an iOS/Android app I've got. There's 3 separate data files that I'd like to be able to edit, and I would like to save them to plist files or xml files. I'm planning on using Core Data in the app. The problems I'm running into:

1). Should this be a Document-Based Application or not?

2). If so, how would I set it up to allow editing of 3 different structures of files?

3). And if so, how would I go about setting the document based app to use regular plist/xml files as the file type instead of some custom file type?

The plan is for the editor to be able to open up and edit the files, and then the saved files can be copied into the project resources of the iOS and Android apps.


Solution

  • 1. Should the app be document-based?

    Yes.

    2. How would one allow editing three different structures of files?

    Choose from any of the following:

    1. Create three dictionaries in the document types list, all three of which reference the same document class.
    2. The same as above, but with windowNibName or makeWindowControllers choosing the UI depending on the document type. In other words, shared model code, but different view hierarchies. (I probably would choose either of the alternatives instead.)
    3. Create three document type dictionaries, each of which has its own document class.

    Which one you choose will depend on just how different the types are.

    You'll probably want to export a UTI for each document type, as well. Xcode will not help you there; you'll need to write each UTI dictionary by hand.

    3. How would I set the document based app to use regular plist/xml files as the file type instead of some custom file type?

    If you export one or more UTIs, you should set the parent UTI(s) of each UTI appropriately, but that's advisory; all it means is you'll be able to open the documents with generic plist or XML editors/viewers.

    Reading in and writing out the data is up to you, in each document class. You will have to use NSPropertyListSerialization, NSXMLParser, PRHXMLParser, NSXMLDocument, or something else, as you see fit; NSDocument does not handle your file format for you.