Type Method

addOfItem(at:withContentsOf:options:)

Creates a version of the file at the specified location.

Declaration

class func addOfItem(at url: URL, withContentsOf contentsURL: URL, options: NSFileVersion.AddingOptions = []) throws -> NSFileVersion

Parameters

url

The location at which to store the new file version.

contentsURL

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

options

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 NSFileVersion.AddingOptions.

outError

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.

Discussion

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.