• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
      • From: Kevin Perry <email@hidden>
References: 
 >NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends) (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Daemon safe SMTP frameworks
  • Next by Date: Re: (Problems) Scaling NSViews with scaleUnitSquareToSize
  • Previous by thread: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
  • Next by thread: Re: NSDocument Serialization (-performSynchronousFileAccessUsingBlock: and friends)
  • Index(es):
    • Date
    • Thread