<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:"
  },
  "title" : "saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:"
}
-->

# saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:

Called after the user has been given the opportunity to select a destination through the modal Save panel.

```
- (void) saveToFile:(NSString *) fileName saveOperation:(NSSaveOperationType) saveOperation delegate:(id) delegate didSaveSelector:(SEL) didSaveSelector contextInfo:(void *) contextInfo;
```

## Discussion

Called after the user has been given the opportunity to select a destination through the modal Save panel presented by [`runModalSavePanel(for:delegate:didSave:contextInfo:)`](/documentation/AppKit/NSDocument/runModalSavePanel(for:delegate:didSave:contextInfo:)). The `delegate` is assigned to the Save panel. If `fileName` is non-`nil`, this method writes the document to `fileName`, sets the document’s file location and document type (if a native type), and clears the document’s edited status. `didSaveSelector` gets called with <doc://com.apple.documentation/documentation/Swift/true> if the document is saved successfully, and <doc://com.apple.documentation/documentation/Swift/false> otherwise. The `saveOperation` is one of the constants in `Constants`. Pass `contextInfo` with the callback.

The `didSaveSelector` callback method should have the following signature:

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

---

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)