You can quit or exit an app with:
NSApp.terminate(self)
If you’re making a macOS menu bar app in Swift and have an option in the dropdown menu to quit the app then your code would look something like:
NSMenuItem(title: "Quit", action: #selector(quitClicked), keyEquivalent: "q")
Menu Bar Item
@objc private func quitClicked() {
NSApp.terminate(self)
}
Function invoked when a user clicks on the menu item
Note: Do not forget to add @objc
in front of the function so that it can be called from #selector
.