Instance Method

writeToURL:atomically:

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

Declaration

- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically;

Parameters

aURL

The location to which to write the receiver's bytes. Only file:// URLs are supported.

atomically

If YES, the data is written to a backup location, and then—assuming no errors occur—the backup location is renamed to the name specified by aURL; otherwise, the data is written directly to aURL. atomically is ignored if aURL is not of a type the supports atomic writes.

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:atomically:, 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:options:error:

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

NSDataWritingOptions

Options for methods used to write data objects.