NSDocument fileWrapperOfType:: invalidates returned wrapper, options?

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

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


    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.

    For some reason, when I try to lazy-load package files located down the wrapper
    hierarchy after saving, they are still available (meaning the sub-wrapper
    objects are there) but the content returned by -regularFileContents 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


    but it doesn't feel right. I'm wondering if there's a better way to make sure
    the wrapper points to the right place once saving is complete.

    Markus Spoettl
previous month june 2012 next month
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Go to today