Re: Checking document structure in NSDocument based app
Re: Checking document structure in NSDocument based app
- Subject: Re: Checking document structure in NSDocument based app
- From: Keary Suska <email@hidden>
- Date: Tue, 27 Nov 2012 09:00:46 -1000
On Nov 27, 2012, at 8:08 AM, Luc Van Bogaert wrote:
> I have a document based app with one NSDocument subclass, and one NSWindowController subclass. NSDocumentController is not subclassed at the moment. The functionality of my application has expanded over time, and so has the internal structure of my document subclass : extra properties and methods have been added. As a result, documents that were created with an early version of my app are no longer 'compatible' with the current version of the application. For instance, I've added bindings using keypaths that don't even exist in these early documents.
>
> I'm now thinking about a way to handle this properly. I would accept the fact that the app is not backward compatible, but I know I should properly handle any requests to open those old document formats. I'm more or less clueless on how to do this. I'm thinking that I may need to subclass NSDocumentController and override addDocument: so I could check against the document version before allowing the app to actually open it.
>
> Any advice on how to do this would be greatly appreciated.
It should be straightforward, as long as you are using keyed encoding. IMHO one should alway stamp documents with at least the app's version number. Smarter developers may use document versioning, although that requires a bit more management. Using a version number allows your app to know exactly how to understand the old format, and allows for an upgrade path.
In the meantime, you can explicitly test for the existence of certain keys using -containsValueForKey: in your initWithCoder: method(s).
HTH,
Keary Suska
Esoteritech, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden