Instance Method

write(toFile:atomically:)

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

Declaration

func write(toFile path: String, atomically useAuxiliaryFile: Bool) -> Bool

Parameters

path

The location to which to write the receiver's bytes. If path contains a tilde (~) character, you must expand it with expandingTildeInPath before invoking this method.

atomically

If true, the data is written to a backup file, and then—assuming no errors occur—the backup file is renamed to the name specified by path; otherwise, the data is written directly to path.

Return Value

true if the operation succeeds, otherwise false.

Discussion

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 File

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.

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

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.