Re: Return values of NSAlert
Re: Return values of NSAlert
- Subject: Re: Return values of NSAlert
- From: Marco S Hyman <email@hidden>
- Date: Tue, 21 Oct 2014 21:35:00 -0700
>
> The suggested alternative is NSAlertFirstButtonReturn, etc., which have values, which very much unlike the actual returned values.
Those values worked for me found by trial an error because the documentation
and headers made no sense at all. I was working in swift and found
this code to work.
var alert = NSAlert()
alert.addButtonWithTitle(NSLocalizedString("SAVE", comment: "Save"))
alert.addButtonWithTitle(NSLocalizedString("CANCEL", comment: "Cancel"))
alert.addButtonWithTitle(NSLocalizedString("DONT_SAVE", comment: "Don't Save"))
alert.messageText = NSLocalizedString("UNSAVED_TITLE", comment: "Unsaved Changes")
alert.informativeText = NSLocalizedString("UNSAVED_DESC", comment: "Unsaved Changes")
alert.beginSheetModalForWindow(window) {
(response: NSModalResponse) -> Void in
switch response {
case NSAlertFirstButtonReturn: // Save
self.save(nil)
case NSAlertSecondButtonReturn: // Cancel
// Close/terminate cancelled
return
default:
// Don't bother saving
break
}
window.documentEdited = false
window.close()
}
NSAlertFirstButtonReturn was the value returned when the first button
added to the NSAlert was pressed, etc.
I don't understand it. I accept that it works (for now, anyway)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden