Skip to content

Instantly share code, notes, and snippets.

@mlabraca
Last active March 2, 2017 17:32
Show Gist options
  • Save mlabraca/17fd372a08395b12e3770c615966b077 to your computer and use it in GitHub Desktop.
Save mlabraca/17fd372a08395b12e3770c615966b077 to your computer and use it in GitHub Desktop.
Cheat sheet for notification center (objc & swift)
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