<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/save(to:ofType:for:delegate:didSave:contextInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)saveToURL:ofType:forSaveOperation:delegate:didSaveSelector:contextInfo:"
  },
  "title" : "save(to:ofType:for:delegate:didSave:contextInfo:)"
}
-->

# save(to:ofType:for:delegate:didSave:contextInfo:)

Saves the contents of the document to a file or file package located by a URL, that is formatted to a specified type, for a particular kind of save operation.

```
func save(to url: URL, ofType typeName: String, for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`url`

The location of the file or file package to which the document contents are saved.

`typeName`

The string that identifies the document type.

`saveOperation`

The type of save operation.

`delegate`

The delegate to which the selector message is sent.

`didSaveSelector`

The selector of the message sent to the delegate.

`contextInfo`

Object passed with the callback to provide any additional context information.

## Discussion

When saving is completed, regardless of success or failure, the method sends the message selected by `didSaveSelector` to the `delegate`, with the `contextInfo` as the last argument. The method selected by `didSaveSelector` must have the same signature as:

```objc
- (void)document:(NSDocument *)document didSave:(BOOL)didSaveSuccessfully  contextInfo:(void  *)contextInfo;
```

The default implementation of this method invokes `[self saveToURL:absoluteURL ofType:typeName forSaveOperation:saveOperation error:&anError]` and, if <doc://com.apple.documentation/documentation/Swift/false> is returned, presents the error to the user in a document-modal panel before messaging the delegate.

## See Also

[`-  saveToURL:ofType:forSaveOperation:error:`](/documentation/AppKit/NSDocument/saveToURL:ofType:forSaveOperation:error:)

Saves the contents of the document to a file or file package located by a URL, formatted to a specified type, for a particular kind of save operation.



---

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)