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

# init(contentsOf:error:)

Initializes a newly allocated dictionary using the keys and values found at a given URL.

```
convenience init(contentsOf url: URL, error: ()) throws
```

## Parameters

`url`

A URL that identifies a resource containing a string representation of a property list whose root object is a dictionary.

`error`

On failure, a reference to the error that occurred.

## Return Value

An initialized dictionary that contains the dictionary at `url`, or `nil` if there is an error or if the contents of the resource are an invalid representation of a dictionary.

## Discussion

The dictionary representation in the file identified by `url` must contain only property list objects ([`NSString`](/documentation/Foundation/NSString), [`NSData`](/documentation/Foundation/NSData), [`NSDate`](/documentation/Foundation/NSDate), [`NSNumber`](/documentation/Foundation/NSNumber), [`NSArray`](/documentation/Foundation/NSArray), or [`NSDictionary`](/documentation/Foundation/NSDictionary) objects). For more details, see [Property List Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html#//apple_ref/doc/uid/10000048i). The objects contained by this dictionary are immutable, even if the dictionary is mutable.

In Swift, this initializer throws if there is an error loading the URL, or if the contents of the resource are an invalid representation of a dictionary.

---

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)