Instance Method

write(toFile:atomically:)

Writes the contents of the receiver to the file specified by a given path.

Declaration

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

Return Value

true if the file is written successfully, otherwise false.

Discussion

Writes the contents of the receiver to the file specified by path (overwriting any existing file at path). path is written in the default C-string encoding if possible (that is, if no information would be lost), in the Unicode encoding otherwise.

If flag is true, the receiver is written to an auxiliary file, and then the auxiliary file is renamed to path. If flag is false, the receiver is written directly to path. The true option guarantees that path, if it exists at all, won’t be corrupted even if the system should crash during writing.

If path contains a tilde (~) character, you must expand it with expandingTildeInPath before invoking this method.

See Also

Related Symbols

func write(toFile: String, atomically: Bool, encoding: UInt)

Writes the contents of the receiver to a file at a given path using a given encoding.