• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Return values of NSAlert
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Return values of NSAlert (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Return values of NSAlert
  • Next by Date: Re: Return values of NSAlert
  • Previous by thread: Return values of NSAlert
  • Next by thread: Re: Return values of NSAlert
  • Index(es):
    • Date
    • Thread