On Nov 27, 2012, at 10:08 , Luc Van Bogaert <luc.van.boga...@me.com> 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.

(a) What are you using to decode saved documents? NSKeyedUnarchiver?

(b) Where is the document version stored? That is, how easy is it to get to the 
document version *first*?

Assuming you're using a keyed unarchiver, you can probably use a combination of 
techniques:

1. Unarchive a value for a particular key, and if it's nil assume this is an 
old-format document, create a default value and continue.

2. Check that there are values for certain key paths, and arrange for 
unarchiving to fail if not. Note that failing is not quite as easy as it seems. 
Your 'initWithCoder:' can return nil, but the thing that triggered it must 
check for nil and fail in its turn. The problem is that nil might be a valid 
result in some cases.

An alternative is to subclass NSKeyedUnarchiver to have a decodeFailed 
property. You still need to check explicitly for failure in every 
'initWithCoder:', but at least it's not ambiguous like checking for nil values.

3. Subclass NSKeyedUnarchiver to have a documentVersion property, and arrange 
for this property to be unarchived first (more or less) and stashed in the 
unarchiver itself. Any subsequently called 'initWithCoder:' method can then 
check the version directly, and either supply a default or make unarchiving 
fail.

4. etc


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to