Created
January 30, 2019 11:42
-
-
Save charlieInDen/5e0d463a2f48cfd5f89c8e878aff9afc to your computer and use it in GitHub Desktop.
After restructuring for writing test cases for NSNotification centre logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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