---
title: "init(contentsOf:options:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsdata/init(contentsof:options:)"
---

# init(contentsOf:options:)

Creates a data object from the data at the provided file URL using specific reading options.

## Declaration

```swift
init(contentsOf url: URL, options readOptionsMask: NSData.ReadingOptions = []) throws
```

## Parameters

- `url`: The location on disk of the data to read.
- `readOptionsMask`: The mask specifying the options to use when reading the data. For more information, see doc://com.apple.foundation/documentation/Foundation/NSData/ReadingOptions.

## Discussion

Discussion important: As this method runs synchronously and blocks the calling thread until it finishes, don’t invoke it from the main thread. Use file coordination or one of the nonblocking file-related APIs instead. If the system can’t create an instance, the initializer may throw in Swift, or return nil in Objective-C.
