---
title: "write(to:ofType:for:originalContentsURL:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nspersistentdocument/write(to:oftype:for:originalcontentsurl:)"
---

# write(to:ofType:for:originalContentsURL:)

Saves changes in the document’s managed object context and saves the document’s persistent store to a given URL.

## Declaration

```swift
nonisolated func write(to absoluteURL: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, originalContentsURL absoluteOriginalContentsURL: URL?) throws
```

## Parameters

- `absoluteURL`: An URL that specifies the new location for the document store. It must not be a relative URL.
- `typeName`: The document type.
- `saveOperation`: The save operation type. See the “Constants” section in doc://com.apple.appkit/documentation/AppKit/NSDocument for possible values.
- `absoluteOriginalContentsURL`: An URL that specifies the location of the original document store.

## Discussion

Discussion note: 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 in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Related Documentation

- [configurePersistentStoreCoordinator(for:ofType:modelConfiguration:storeOptions:)](appkit/nspersistentdocument/configurepersistentstorecoordinator(for:oftype:modelconfiguration:storeoptions:).md)

### Document Content Management

- [read(from:ofType:)](appkit/nspersistentdocument/read(from:oftype:).md)
- [revert(toContentsOf:ofType:)](appkit/nspersistentdocument/revert(tocontentsof:oftype:).md)
