Contents

init(contentsOf:)

Creates a data object from the data at the specified file URL, or returns nil if the system can’t create one.

Declaration

init?(contentsOf url: URL)

Parameters

  • url:

    The location on disk of the data to read.

Discussion

If you specify a malformed URL or the referenced location doesn’t exist on disk, the initializer fails and returns nil. To handle such errors, use NSData/init(contentsOfURL:options:)-5abi3 instead.