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

# runModalSavePanel(for:delegate:didSave:contextInfo:)

Presents a modal Save panel to the user, then tries to save the document if the user approves the operation.

```
func runModalSavePanel(for saveOperation: NSDocument.SaveOperationType, delegate: Any?, didSave didSaveSelector: Selector?, contextInfo: UnsafeMutableRawPointer?)
```

## Parameters

`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, or has been canceled, sends the message selected by `didSaveSelector` to the `delegate`, with `contextInfo` as the last argument. The method selected by `didSaveSelector` must have the same signature as:

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

Invoked from [`save(withDelegate:didSave:contextInfo:)`](/documentation/AppKit/NSDocument/save(withDelegate:didSave:contextInfo:)), and from the [`saveAs(_:)`](/documentation/AppKit/NSDocument/saveAs(_:)) and [`saveTo(_:)`](/documentation/AppKit/NSDocument/saveTo(_:)) action methods. The default implementation of this method first makes sure that any editor registered using the Cocoa Bindings [`NSEditorRegistration`](/documentation/AppKit/NSEditorRegistration) informal protocol has committed its changes, then creates a Save panel, adds a standard file format accessory view (if there is more than one file type for the user to choose from and [`shouldRunSavePanelWithAccessoryView`](/documentation/AppKit/NSDocument/shouldRunSavePanelWithAccessoryView) returns <doc://com.apple.documentation/documentation/Swift/true>), sets various attributes of the panel, invokes [`prepareSavePanel(_:)`](/documentation/AppKit/NSDocument/prepareSavePanel(_:)) to provide an opportunity for customization, then presents the panel. If the user approves the panel, the default implementation sends the message [`save(to:ofType:for:delegate:didSave:contextInfo:)`](/documentation/AppKit/NSDocument/save(to:ofType:for:delegate:didSave:contextInfo:)).

For backward binary compatibility with Mac OS v10.3 and earlier, the default implementation of this method instead invokes the deprecated [`saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:`](/documentation/AppKit/NSDocument/saveToFile:saveOperation:delegate:didSaveSelector:contextInfo:) if it is overridden, even if the user cancels the panel.

---

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)