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];
Let's StartOpen Main. storyboard and add two buttons on View controller Scene. These buttons are used to display two types of alert i.e single button and two button alert. Select Cocoa Touch Class from Source and click Next.
Build and present custom alerts to your users Presenting system alerts on SwiftUI is super simple. Just call an instance method alert and pass a few parameters, and you are done. But the system alerts that come up are too basic with the non-customizable default design.
XCODE 10, IOS 12 And Swift 4 and above :
1. simple alert view with no action on buttons in an alert.
let alert = UIAlertController(title: "Error", message: "Something Went Wrong", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default))
self.present(alert, animated: true)
2. Alert with actions on ok and cancel button:
let refreshAlert = UIAlertController(title: "Punch Out", message: "You Will Will Punch Out", preferredStyle: UIAlertController.Style.alert)
refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
print("Handle Ok logic here")
}))
refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
print("Handle Cancel Logic here")
refreshAlert .dismiss(animated: true, completion: nil)
}))
self.present(refreshAlert, animated: true, completion: nil)
For more customization Refer to this StackOverflow Answer
Swift 3 iOS 10
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With