On 2011 Aug 08, at 09:29, Kevin Perry wrote:

> You may be able to work around this problem by overriding 
> -autosaveWithImplicitCancellability:completionHandler: instead (also?) and 
> doing the same approach of delaying NSDocument's code until once you've 
> completed the background work.

Thank you, Kevin.  That seems to work; at least, it has worked for a day.

As usual when dealing with NSDocument, the answer is to "override as high as 
possible".

I just submitted Document Feedback suggesting that this document

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Articles/ObjectInteractions.html

get another excellent diagram like the others in there, showing how Autosave In 
Place works.  We would have gotten here faster!

Jerry


Here's the revised code for anyone else playing with customized autosave.  Now 
simpler and safer, because we're only dealing with autosave…

/*!
 @brief    Override of new autosave method invoked by Cocoa
 when running in Mac OS X 10.7 or later.
 */
- 
(void)autosaveWithImplicitCancellability:(BOOL)autosavingIsImplicitlyCancellable
                         completionHandler:(void (^)(NSError 
*errorOrNil))completionHandler {
    if ([self dataModelChangesAreNowInProgressOrWhatever]) {
        if (autosavingIsImplicitlyCancellable) {
            completionHandler([NSError errorWithDomain:NSCocoaErrorDomain
                                                  code:NSUserCancelledError
                                              userInfo:nil]) ;
            return ;
        }
    }

    <snip>
    Insert code here to queue an operation or block to be run when other
    tasks changing the data model are completed.  If not a using modern
    block-handling method, you may need Block_copy(completionHandler).
    </snip>
}


/*!
 @brief    Real autosaving method, invoked when operation or block is dequeued.
 */
- (void)reallyAutosaveWithCompletionHandler:(void (^)(NSError 
*errorOrNil))completionHandler {
    [super autosaveWithImplicitCancellability:NO
                            completionHandler:completionHandler] ;
    // If you did Block_copy(), …
    Block_release(completionHandler) ;
}



_______________________________________________

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