Instance Method

write(to:options:)

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

Declaration

func write(to url: URL, options writeOptionsMask: NSData.WritingOptions = []) throws

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 NSData.WritingOptions.

Return Value

true if the operation succeeds, otherwise false.

Discussion

Since at present only file:// URLs are supported, there is no difference between this method and write(toFile:options:), 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 FileHandle instead. For more information, seeSecuring File Operations in Secure Coding Guide.

See Also

Writing Data to a File

func write(toFile: String, atomically: Bool)

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

func write(toFile: String, options: NSData.WritingOptions = [])

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

func write(to: URL, atomically: Bool)

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

struct NSData.WritingOptions

Options for methods used to write data objects.