Skip to content

Instantly share code, notes, and snippets.

@Cykelero
Created March 7, 2023 14:23
Show Gist options
  • Save Cykelero/1ff3a0819d52ab1d1904845452b8ddfd to your computer and use it in GitHub Desktop.
Save Cykelero/1ff3a0819d52ab1d1904845452b8ddfd to your computer and use it in GitHub Desktop.
A tiny extension to make switching on NSAlert responses easier
extension NSApplication.ModalResponse {
func button(within alert: NSAlert) -> NSButton? {
let buttonIndex =
self.rawValue
- NSApplication.ModalResponse.alertFirstButtonReturn.rawValue
return alert.buttons[safeIndex: buttonIndex]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment