A Medium blog post for NSNotificationCenter
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Blog_NSNotificationCenter.playground
LICENSE
README.md

README.md

Swift: NSNotifcationCenter protocol

Observer pattern made better-er

NSNotificationCenter has been around since the dawn of the iOS SDK and it’s been a popular tool amongst developers for just as long. For those who dont know, it’s based off the concept conveniently named “Observer pattern”, which is part of the behavioural group of software design patterns.

extension Selector {
    static let makeCoffeeNotification = #selector(Customer.drink(_:))
}

class Customer {
    @objc func drink(notification: NSNotification) {
        print("Mmm... Coffee")
    }
}


let customer = Customer()

Barista.addObserver(customer, selector: .makeCoffeeNotification, notification: .makeCoffee)

Barista.postNotification(.makeCoffee)
// prints: Mmm... Coffee

Barista.removeObserver(customer, notification: .makeCoffee)

Read more

Swift Functional Programming: Kinda like reverse Fight Club for developers