On Wed, Sep 28, 2011 at 10:55 PM, Kyle Sluder <kyle.slu...@gmail.com> wrote: > I'd really appreciate if the documentation spelled out exactly how > NSDocument uses these methods.
To give an example of a specific NSDocument usage that I'd like to know about: how does asynchronous saving use -performAsynchronousFileAccessUsingBlock:? I'm envisioning something like this: - (void)saveToURL:(NSURL *)url ofType:(NSString *)type forSaveOperation:(NSSaveOperation)op completionHandler:(void (^)(NSError *errorOrNil))completionHandler { id saveToken = [self changeCountTokenForSaveOperation:op]; if ([self canAsynchronouslyWriteToURL:url ofType:type forSaveOperation:op]) { [self performAsynchronousFileAccessUsingBlock:(void (^fileAccessCompletionHandler)(void)) { dispatch_async(backgroundQueue, ^{ NSError *error; BOOL success; success = [self writeSafelyToURL:url ofType:type forSaveOperation:op error:&error]; fileAccessCompletionHandler(); if (success) [self continueAsynchronousWorkOnMainThreadUsingBlock:^{ [self setFileURL:url]; [self setFileModificationDate:[NSDate date]]; [self setFileType:type]; [self setAutosavedContentsFileURL:url]; [self updateChangeCountWithToken:token forSaveOperation:op]; completionHandler(nil); }]; else [self continueAsynchronousWorkOnMainThreadUsingBlock:^{ completionHandler(error); }]; }); WaitForUnblockUserInteraction(); }]; } } Am I on the right track here? --Kyle Sluder _______________________________________________ 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