<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSData/init(contentsOf:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSData(im)initWithContentsOfURL:options:error:"
  },
  "title" : "init(contentsOf:options:)"
}
-->

# init(contentsOf:options:)

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

```
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 [`NSData.ReadingOptions`](/documentation/Foundation/NSData/ReadingOptions).

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)