Initializer

init(contentsOf:)

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

Declaration

init?(contentsOf url: URL)

Parameters

aURL

The URL from which to read data

Return Value

An NSData object initialized with the data from the location specified by aURL.

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

init?(contentsOfFile: String)

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

init(contentsOfFile: String, options: NSData.ReadingOptions = [])

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

init(contentsOf: URL, options: NSData.ReadingOptions = [])

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

struct NSData.ReadingOptions

Options for methods used to read data objects.

init?(contentsOfMappedFile: String)

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

Deprecated
class func dataWithContentsOfMappedFile(String)

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

Deprecated