I have a document-based app (Core Data, but that isn't important here) that can 
have fairly large documents. Migrating these documents from an old format to 
the new one can take several seconds (to decode, transform and re-encode data), 
so I need to do it off the main thread. It seems to work if I create an 
NSOperation to do the migration in the 
openDocumentWithContentsOfURL:display:error: method of my NSDocumentController 
subclass.

So if a document needs migration, this method returns nil with an 
NSCocoaErrorDomain NSUserCancelledError, queues the NSOperation, and then after 
the asynchronous migration completes, [super 
openDocumentWithContentsOfURL:display:error:] is called (on the main thread) to 
open the document.

While the migration is in progress, a modeless dialog is shown with a progress 
indicator and cancel button, and further calls to open the same document are 
ignored (returns NSCocoaErrorDomain NSUserCancelledError).

My question is: Will this strategy miss (or miss-handle) any use cases on Snow 
Leopard or Lion?  Can openDocumentWithContentsOfURL:display:error: ever be 
called off the main thread in response to user actions (assuming my code 
doesn't do this)?

NOTE: My override of 
reopenDocumentForURL:withContentsOfURL:display:completionHandler: does not 
migrate documents since it would be confusing to launch the app and have a 
migration start immediately. So if it is called with a document that needs 
migration, it does nothing.

Thanks for any feedback.

Dave_______________________________________________

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

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

Reply via email to