• 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
NSDocument package saving invalidates wrapper? Options?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSDocument package saving invalidates wrapper? Options?


  • Subject: NSDocument package saving invalidates wrapper? Options?
  • From: Markus Spoettl <email@hidden>
  • Date: Thu, 23 Aug 2012 15:12:21 +0200

I have an NSDocument based app that has uses packages do to store a complex structure.

When I open a document, I keep the wrapper around handed to the document in

-readFromFileWrapper:ofType:error:

in order to lazy-load parts of the package when my app needs them. Similarly, I keep the wrapper when saving (which is the same object unless it's a new document that didn't have a wrapper before). And here the trouble starts.

When I try to lazy-load package files after saving by requesting -regularFileContents on the corresponding wrapper that are located somewhere down the wrapper hierarchy, they are still available (meaning the sub-wrapper objects are there) but the content returned is nil.

The documentation states that this can happen when the user moves the file after the wrapper has been created. I suspect that this is a side effect of safe-saving, which writes temporary files and moves them into place when everything worked out correctly.

I'm fixing this by calling -readFromURL:options:error: on the document package's root wrapper in the completionHandler of NSDocument's

-saveToURL:forSaveOperation:completionHandler:

before calling the original completionHandler (I'm pasting the relevant code below).

As it's not mentioned in the documentation anywhere (meaning saving packages will invalidate wrappers), it doesn't feel quite right. I've been using this a couple of months now without adverse effects, though.

I'm wondering this is expected behavior and/or if there's a better way to make sure the wrapper points to the right place once saving is complete.

I'm using the 10.7 SDK.

Regards
Markus

- (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName
                     forSaveOperation:(NSSaveOperationType)saveOperation
                    completionHandler:(void (^)(NSError *))completionHandler
{
    [super saveToURL:url ofType:typeName
               forSaveOperation:saveOperation
             completionHandler:^(NSError *error) {

         if (error == nil) {
            [rootFileWrapper readFromURL:url options:0 error:&error];
         }

         completionHandler(error);
    }];
}

_______________________________________________

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

  • Prev by Date: Re: Sandboxing die.die.die
  • Next by Date: DisplayReconfigurationCallBack with nil cgDisplayID
  • Previous by thread: Source List type OutlineView and bindings.
  • Next by thread: DisplayReconfigurationCallBack with nil cgDisplayID
  • Index(es):
    • Date
    • Thread