Instance Method

writeToURL:options:error:

Writes the data object's bytes to the location specified by a given URL.

Declaration

- (BOOL)writeToURL:(NSURL *)url options:(NSDataWritingOptions)writeOptionsMask error:(NSError * _Nullable *)errorPtr;

Parameters

aURL

The location to which to write the receiver's bytes.

mask

A mask that specifies options for writing the data. Constant components are described in NSDataWritingOptions.

errorPtr

If there is an error writing out the data, upon return contains an error object that describes the problem.

Return Value

YES if the operation succeeds, otherwise NO.

Discussion

Since at present only file:// URLs are supported, there is no difference between this method and writeToFile:options:error:, except for the type of the first argument.

This method may not be appropriate when writing to publicly accessible files. To securely write data to a public location, use NSFileHandle instead. For more information, seeSecuring File Operations in Secure Coding Guide.

See Also

Writing Data to a File

writeToFile:atomically:

Writes the data object's bytes to the file specified by a given path.

writeToFile:options:error:

Writes the data object's bytes to the file specified by a given path.

writeToURL:atomically:

Writes the data object's bytes to the location specified by a given URL.

NSDataWritingOptions

Options for methods used to write data objects.