<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSRunAlertPanel",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:@F@NSRunAlertPanel"
  },
  "title" : "NSRunAlertPanel"
}
-->

# NSRunAlertPanel

Creates an alert panel.

```
extern NSInteger NSRunAlertPanel(NSString *title, NSString *msgFormat, NSString *defaultButton, NSString *alternateButton, NSString *otherButton, ...);
```

## Discussion

Creates and runs an alert panel (or dialog) with the title of `title` and buttons with titles of `defaultButton`, `alternateButton`, and `otherButton`. The optional alert message specified by `msgFormat` should be a static value that can consist of variable values using a format string (list any necessary arguments for this formatted string at the end of the function’s argument list), an unformatted string, or an empty string (`@""`), but not `nil`. Note that passing an untrusted string in `msgFormat` can lead to security issues. See the description of [`NSBeginAlertSheet`](/documentation/AppKit/NSBeginAlertSheet) for information on layout of buttons, default parameters, and possible return values. `NSRunAlertPanel` runs the panel in a modal event loop.

A Command-D key equivalent for the “Don’t Save” button is provided, if one is found. The button titles are searched for the localized value for “Don’t Save.” If a match is found, that button is assigned a Command-D key equivalent, provided it is not the default button.

If you create a modal panel using [`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:)) or [`beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:)`](/documentation/AppKit/NSApplication/beginSheet(_:modalFor:modalDelegate:didEnd:contextInfo:)), you can assign the key equivalent yourself, using [`keyEquivalent`](/documentation/AppKit/NSButton/keyEquivalent) and [`keyEquivalentModifierMask`](/documentation/AppKit/NSButton/keyEquivalentModifierMask).

This function not only creates the panel; it also puts the panel onscreen and runs it using the [`runModal(for:)`](/documentation/AppKit/NSApplication/runModal(for:)) method defined in the [`NSApplication`](/documentation/AppKit/NSApplication) class. This method sets up a modal event loop that causes the panel to remain onscreen until the user clicks one of its buttons. This function then removes the panel from the screen list and returns a value that indicates which of the three buttons the user clicked. For efficiency, this function creates the panel the first time it’s called and reuses it on subsequent calls, reconfiguring it if necessary.

---

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)