Type Method

dataWithContentsOfURL:

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

Declaration

+ (instancetype)dataWithContentsOfURL:(NSURL *)url;

Parameters

aURL

The URL from which to read data.

Discussion

Use this method to convert 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.

This method may fail and return nil for various reasons, like bad URLs and file-not-found errors. If you want to handle these errors, use dataWithContentsOfURL:options:error: instead.

See Also

Reading Data from a File

+ dataWithContentsOfFile:

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

+ dataWithContentsOfFile:options:error:

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

+ dataWithContentsOfURL:options:error:

Creates 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 a data object from the mapped file at a given path.

Deprecated

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