Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
- Subject: Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
- From: Kyle Sluder <email@hidden>
- Date: Wed, 28 Sep 2011 23:23:42 -0700
On Wed, Sep 28, 2011 at 10:55 PM, Kyle Sluder <email@hidden> 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 (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