Skip to content

Instantly share code, notes, and snippets.

@andyyhope
Last active June 17, 2016 16:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andyyhope/ec73810237fbf2a1a641c22e4015fe8e to your computer and use it in GitHub Desktop.
Save andyyhope/ec73810237fbf2a1a641c22e4015fe8e to your computer and use it in GitHub Desktop.
extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
let customer = Customer()
Barista.addObserver(customer, selector: .coffeeMadeNotification, notification: .coffeeMade)
Barista.postNotification(.coffeeMade)
// prints: Mmm... Coffee
Barista.removeObserver(customer, notification: .coffeeMade)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment