Skip to content

Instantly share code, notes, and snippets.

@charlieInDen
Created January 30, 2019 11:39
Show Gist options
  • Save charlieInDen/d4710a9df7f174a7ceaf2e7426d28cdd to your computer and use it in GitHub Desktop.
Save charlieInDen/d4710a9df7f174a7ceaf2e7426d28cdd to your computer and use it in GitHub Desktop.
Default implementation of sending notification and adding observer before restructuring to write test cases
class CurrentLocationProvider {
static let authChangedNotification = Notification.Name("AuthChanged")
func notifyAuthChanged() {
let name = CurrentLocationProvider.authChangedNotification
NotificationCenter.default.post(name: name, object: self)
}
}
class PointsOfInterestTableViewController {
var observer: AnyObject?
init() {
let name = CurrentLocationProvider.authChangedNotification
observer = NotificationCenter.default.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