Type Method


Creates a version of the file at the specified location.


+ (NSFileVersion *)addVersionOfItemAtURL:(NSURL *)url withContentsOfURL:(NSURL *)contentsURL options:(NSFileVersionAddingOptions)options error:(NSError * _Nullable *)outError;



The location at which to store the new file version.


The URL that specifies the file to use for the version contents.


Specify 0 for this parameter if you want to create a copy of the file at the location specified by the url parameter. Alternatively, specify one of the constants described in NSFileVersionAddingOptions.


On input, a pointer to an error object. If an error occurs, this pointer is set to an NSError object with information about the error.

Return Value

The file version object representing the new version or nil if an error occurred.


You can use this method to save a version of your file to the location specified by the url parameter. The contents of the file are taken from the contentsURL parameter, whose value may be the same as the url parameter.

You should always add file versions as part of a coordinated write operation to a file. In other words, always call this method from a block passed to a file coordinator object to initiate a write operation. Doing so ensures that no other processes are operating on the file while you save the version to its new location.