2秒後に自動で閉じる
Swift
let alert: UIAlertController = UIAlertController(title: "", message: "Alert", preferredStyle: .Alert)
self.presentViewController(alert, animated: true) { () -> Void in
let delay = 2.0 * Double(NSEC_PER_SEC)
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
dispatch_after(time, dispatch_get_main_queue(), {
self.dismissViewControllerAnimated(true, completion: nil)
})
}
意外と簡単便利。