Working with Notification Center in iOS 10

While using the iOS 10 SDK and Xcode 8, I have found working with NSNotificationCenter, now named just NotificationCenter, to be a much more pleasing experience.

First, new in iOS 9, you can forget about removing observers in the deinit method (or the deallac method in Objective-C). But, only if you don’t plan on supporting iOS 8 or earlier.

Secondly, new in iOS 10, a NotificationCenter observer name is no longer a string, it is now a NotificationCenter.Name. Which means you can extend the struct with your own properties and get compiler checking and code completion.

extension Notification.Name {
    static let receivedOAuthCode = Notification.Name("receivedOAuthCode")

The name of the observer is now .receivedOAuthCode instead of "receivedOAuthCode".

NotificationCenter.default.addObserver(self, selector: #selector(safariLogin(_:)), name: .receivedOAuthCode, object: nil)