Type Method

dataWithContentsOfURL:options:error:

Creates and returns a data object containing the data from the location specified by a given URL.

Declaration

+ (instancetype)dataWithContentsOfURL:(NSURL *)url options:(NSDataReadingOptions)readOptionsMask error:(NSError * _Nullable *)errorPtr;

Parameters

aURL

The URL from which to read data.

mask

A mask that specifies options for reading the data. Constant components are described in NSDataReadingOptions.

errorPtr

If there is an error reading in the data, upon return contains an error object that describes the problem.

Return Value

A data object that holds data located at aURL. Returns nil if the data object could not be created.

Discussion

Use this method to converting data:// URLs to NSData objects. You can also use it to read short files synchronously. If you need to read potentially large files, use inputStreamWithURL: to open a stream, then read the file incrementally.

If you need to know the reason for failure, use dataWithContentsOfURL:options:error:.

See Also

Reading Data from a File

dataWithContentsOfFile:

Creates and returns a data object by reading every byte from the file at a given path.

dataWithContentsOfFile:options:error:

Creates and returns a data object by reading every byte from the file at a given path.

dataWithContentsOfURL:

Returns a data object containing the data from the location specified by a given URL.

initWithContentsOfFile:

Initializes a data object with the content of the file at a given path.

initWithContentsOfFile:options:error:

Initializes a data object with the content of the file at a given path.

initWithContentsOfURL:

Initializes a data object with the data from the location specified by a given URL.

initWithContentsOfURL:options:error:

Initializes a data object with the data from the location specified by a given URL.

NSDataReadingOptions

Options for methods used to read data objects.

initWithContentsOfMappedFile:

Initializes a data object with the contents of the mapped file specified by a given path.

Deprecated
dataWithContentsOfMappedFile:

Creates and returns a data object from the mapped file at a given path.

Deprecated