Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsavit1/712f0b2d3f01c4dedf996fff73b3f592 to your computer and use it in GitHub Desktop.
Save hsavit1/712f0b2d3f01c4dedf996fff73b3f592 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