[swift] NSNotificationを利用してイベントドリブンで処理を開始する
NSNotificationを利用してイベントドリブンで処理を開始する
ある処理がバックグラウンドで走っていて、その処理が終了したら次の処理を行うなど
NSNotificationを利用してイベントドリブンで処理を開始したい時は、以下のように実装する
Notification送信側
let str = "eventCompleted" let n : NSNotification = NSNotification(name: str, object: self) NSNotificationCenter.defaultCenter().postNotification(n)
Notification受信側
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self._recieveComplete), name: "eventCompleted", object: nil)
}
func _recieveComplete(){
//通知受信時の処理を書く
}