<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileWrapper/write(to:options:originalContentsURL:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileWrapper(im)writeToURL:options:originalContentsURL:error:"
  },
  "title" : "write(to:options:originalContentsURL:)"
}
-->

# write(to:options:originalContentsURL:)

Recursively writes the entire contents of a file wrapper to a given file-system URL.

```
func write(to url: URL, options: FileWrapper.WritingOptions = [], originalContentsURL: URL?) throws
```

## Parameters

`url`

URL of the file-system node to which the file wrapper’s contents are written.

`options`

Option flags for writing to the node located at `url`. See [`FileWrapper.WritingOptions`](/documentation/Foundation/FileWrapper/WritingOptions) for possible values.

`originalContentsURL`

The location of a previous revision of the contents being written. The default implementation of this method attempts to avoid unnecessary I/O by writing hard links to regular files instead of actually writing out their contents when the contents have not changed.  The child file wrappers must return accurate values when its [`filename`](/documentation/Foundation/FileWrapper/filename) property is accessed for this to work. Use the `NSFileWrapperWritingWithNameUpdating` writing option to increase the likelihood of that.

    Specify     `nil`     for this parameter if there is no earlier version of the contents or if you want to ensure that all the contents are written to files.

## Discussion

> Handling Errors in Swift:
> In Swift, this method returns `Void` and is marked with the `throws` keyword to indicate that it throws an error in cases of failure.
> 
> You call this method in a `try` expression and handle any errors in the `catch` clauses of a `do` statement, as described in [Error Handling](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

## See Also

[`-  readFromURL:options:error:`](/documentation/Foundation/FileWrapper/read(from:options:))

Recursively rereads the entire contents of a file wrapper from the specified location on disk.

[`filename`](/documentation/Foundation/FileWrapper/filename)

The filename of the file wrapper object



---

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)