Gokhan Dilek Gokhan Dilek - 11 months ago 59
Objective-C Question

Create a simple Alert in swift

It looks like alertstatus cannot be used in swift.

Can you guys please help me implementing an alternative solution to the code below?

[self alertStatus:@"Message!" :@"Alert title" :0];

Answer Source

Try with following code

let alert = UIAlertView()
alert.title = "Title"
alert.message = "My message"

But in iOS 8

UIAlertView is deprecated. So use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert. it should be

var alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)