Last active
August 29, 2015 14:15
-
-
Save mono0926/5af3fcdc872eb506002f to your computer and use it in GitHub Desktop.
Register and remove notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extension | |
extension UIViewController { | |
func observeDidBecomeActive(action: Selector) -> () -> () { | |
return observeNotification(action, name: UIApplicationDidBecomeActiveNotification) | |
} | |
private func observeNotification(action: Selector, name: String) -> () -> () { | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: action, name: name, object: nil) | |
return { | |
return NSNotificationCenter.defaultCenter().removeObserver(self, name: name, object: nil) | |
} | |
} | |
} | |
// 登録 | |
let removeObserverClosure = observeDidBecomeActive("didBecomeActive") | |
// どこかで解除 | |
removeObserverClosure() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment