Skip to content

Instantly share code, notes, and snippets.

@charlieInDen
Created January 30, 2019 11:42
Show Gist options
  • Save charlieInDen/5e0d463a2f48cfd5f89c8e878aff9afc to your computer and use it in GitHub Desktop.
Save charlieInDen/5e0d463a2f48cfd5f89c8e878aff9afc to your computer and use it in GitHub Desktop.
After restructuring for writing test cases for NSNotification centre logic
class CurrentLocationProvider {
static let authChangedNotification = Notification.Name("AuthChanged")
let notificationCenter: NotificationCenter
init(notificationCenter: NotificationCenter = .default) {
self.notificationCenter = notificationCenter
}
func notifyAuthChanged() {
let name = CurrentLocationProvider.authChangedNotification
notificationCenter.post(name: name, object: self)
}
}
class PointsOfInterestTableViewController {
let notificationCenter: NotificationCenter
var observer: AnyObject?
init(notificationCenter: NotificationCenter = .default) {
self.notificationCenter = notificationCenter
let name = CurrentLocationProvider.authChangedNotification
observer = notificationCenter.addObserver(forName: name, object: nil, queue: .main) { [weak self] _ in
self?.handleAuthChanged()
}
}
var didHandleNotification = false
func handleAuthChanged() {
didHandleNotification = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment