macoscocoasave-asnsfilewrapper

Saving document using NSFileWrapper


I'm developing an document-based application that allow users to insert images, movies to make compositions.

When saving the document, I create a directoryFileWrapper in which I put the xml representation of my project, and one fileWrapper for each images/movies using the original path (if document is not saved yet) or the it's relative path inside the package.

Once it's saved, users can move the document to another location/mac and still have access to their content.

If user do a "SaveAsOperation", and save it at the same location, the document is first deleted, and then I have to recreate it. The problem is that I can't recreate the fileWrappers using the relative path, as the document itself is already deleted.

Is there a way to prevent it to happen? What's the right way to save existing files into packages?


Solution

  • The way to do it is:

    in .h

    In the init:

    Each time you want to add a file in the wrapper:

    In -readFromFileWrapper:(NSFileWrapper *)inFileWrapper ofType:error:

    In -fileWrapperOfType:error:

    If you also want to use NSFileWrapper, this link may be helpful https://www.cocoanetics.com/2012/09/back-on-mac-os-x-tutorial-for-ios-developers/ and the github repo is https://github.com/Cocoanetics/Examples