Question

This is probably a naive question - but I want to double check to avoid wasting time with UIDocument if it doesn't do what I want.

Background: I have an app for which I have created a simple file system to save out user created documents as plists. I have my encoding/decoding all working. I am using some primitive types and handle that with the appropriate encoder method. I have a naming system and save the plists to a custom directory in the Library directory since these are docs the user should not have direct access to. (they can export their data to the documents directory if they so choose.

I started thinking about "autosave" and then discovered UIDocument - looks pretty great.

So given the above, does it seem like I can use UIDocument? What I save out is a custom class "Project" instance derived from NSObject. It contains a bunch of NSMutable arrays which contain instances of custom classes, NSDictionaries etc. I'm going through this UIDocument tutorial now: http://www.raywenderlich.com/6015/beginning-icloud-in-ios-5-tutorial-part-1 but don't want to discover that it's not going to work because of my data, etc.

Update:(for those reading along at home... ;-) Made some progress with this. UIDocument uses NSKeyedArchiver rather than NSCoder (Wrong - see answer below) but the encoding method names are the same so it was easy to adjust what I already had. Have been able to save out a plist that looks like it is capturing all the data - but I won't know until I try to read it all back in. Getting an error that I haven't sorted out:

NSFileCoordinator: A surprising server error was signaled. Details: Connection invalid

Not so surprising since I am saving locally not clear why it is trying to connect to iCloud at all. Hopefully I can switch that off.

Was it helpful?

Solution

I'm not sure where you get the thing about UIDocument using NSKeyedArchiver. For a simple implementation all you need to do is provide an NSData representation of your document contents -- it doesnt matter whether you generate that data from your model objects with NSCoder, NSKeyedArchiver, NSPropertyListSerialization, or some custom scheme.

Given that, I don't see any reason it shouldn't work with the data model you describe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top