<!--
{
  "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/write(to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(im)writeToURL:error:"
  },
  "title" : "write(to:)"
}
-->

# write(to:)

Writes a property list representation of the contents of the dictionary to a given URL.

```
func write(to url: URL) throws
```

## Parameters

`url`

The URL to which to write the dictionary.

## Discussion

This method recursively validates that all the contained objects are property list objects (instances of [`NSData`](/documentation/Foundation/NSData), [`NSDate`](/documentation/Foundation/NSDate), [`NSNumber`](/documentation/Foundation/NSNumber), [`NSString`](/documentation/Foundation/NSString), [`NSArray`](/documentation/Foundation/NSArray), or [`NSDictionary`](/documentation/Foundation/NSDictionary)) before writing out the file. The method throws an error if all the objects are not property list objects, because the resulting output wouldn’t be a valid property list.

If the dictionary’s contents are all property list objects, you can use the location written by this method to initialize a new dictionary with the instance method `NSDictionary/init(contentsOfURL:)-4pv16`.

If you need greater control over the property list representation, use [`PropertyListSerialization`](/documentation/Foundation/PropertyListSerialization) instead.

For more information about property lists, see [Property List Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html#//apple_ref/doc/uid/10000048i).

---

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)