Tuesday, January 27, 2015

Alert Messages with Swift

Here is a quick look at using a modal alert window with swift for Mac OS X



The main window has a simple button action to present a basic modal alert with a text string.

the code to do this in swift is:

@IBAction func btnShowAlert(sender: AnyObject)
        {
            var myAlert:NSAlert = NSAlert()
            myAlert.messageText = "Alert Text Here."
            myAlert.runModal()

    }


Alerts can be more in depth than this. This was just the basics to show how easy they are to add and use in swift. Alerts can also sheet from the main window by using;

beginSheetModalForWindow()

Instead of using the runModal()


Happy Coding;)

No comments:

Post a Comment