Instance Method

writeToFile:options:error:

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

Declaration

- (BOOL)writeToFile:(NSString *)path options:(NSDataWritingOptions)writeOptionsMask error:(NSError * _Nullable *)errorPtr;

Parameters

path

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

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.

- writeToURL:atomically:

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

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

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software