I want to do as my question states. I've copied code on the subject and pasted it to playground, but each time, after the paste, xcode/playground locks up xcode which requires a reboot. I'm running the latest version of xCode and OS XI, and 've copied several versions of this,. All lock up xcode. The lastest attempt follows:
func dialogOKCancel(question: String, text: String) -> Bool {
let myPopup: NSAlert = NSAlert()
myPopup.messageText = question
myPopup.informativeText = text
myPopup.alertStyle = NSAlertStyle.warning
myPopup.addButton(withTitle: "OK")
myPopup.addButton(withTitle: "Cancel")
return myPopup.runModal() == NSAlertFirstButtonReturn
}
I plan to alert the application users of an input error, so they can correct it. In this mode, I'll delete the line to show the Cancel button.
What do I need to do to make this work?
Here is an example that works (tested in playGround), Swift 2.2
func errorReadingResults(question: String, text: String) -> Bool {
let alert = NSAlert()
alert.messageText = question
alert.informativeText = text
alert.addButtonWithTitle("OK")
alert.addButtonWithTitle("Cancel")
alert.alertStyle = .WarningAlertStyle
return alert.runModal() == NSAlertFirstButtonReturn
}
let x = errorReadingResults("Error.", text: "Impossible")
Did you copy this in a clean playground ? Or after some existing code, where maybe the problem is.