In some cases my applications needs to display muliple Alert messages. Error messages are gathered on start and needs to be displayed to the user one at a time. When the first one is acknowledged, the next one should be presented. The problem is that they all try to execute at the same time, obviously. Is there a smart way to do this synchronously? Here is some code that simply describes what I want to do:
var errors : [NSError]!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let error1 = NSError(domain: "Test1", code: 1, userInfo: [NSLocalizedFailureReasonErrorKey : "Test1 reason."])
let error2 = NSError(domain: "Test2", code: 2, userInfo: [NSLocalizedFailureReasonErrorKey : "Test2 reason."])
let error3 = NSError(domain: "Test3", code: 2, userInfo: [NSLocalizedFailureReasonErrorKey : "Test3 reason."])
errors = [error1, error2, error3]
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
for error in errors {
self.showAlert(error)
}
}
func showAlert(error: NSError) {
var alert = UIAlertController(title: error.domain, message: error.localizedDescription, preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:nil))
self.presentViewController(alert, animated: true, completion: nil)
}