Last active
March 2, 2017 17:32
-
-
Save mlabraca/17fd372a08395b12e3770c615966b077 to your computer and use it in GitHub Desktop.
Cheat sheet for notification center (objc & swift)
This file contains hidden or 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
Post notification: | |
* swift: | |
NotificationCenter.default.post(name: .onCountryChanged, object: nil) | |
* objc: | |
[[NSNotificationCenter defaultCenter] postNotificationName:@"on-country-changed" object:nil]; | |
Register notification: | |
* swift: | |
NotificationCenter.default.addObserver(self, selector: #selector(self.someSelector), name: .onCountryChanged, object: nil) | |
* objc: | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someSelector) name:@"on-country-changed" object:nil]; | |
Remove notification: | |
* swift: | |
NotificationCenter.default.removeObserver(self, name: .onCountryChanged, object: nil) | |
* objc: | |
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"on-country-changed" object:nil]; | |
Create Notification by name: | |
extension Notification.Name { | |
static let onCountryChanged = Notification.Name("on-country-changed") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment