Created
January 30, 2019 11:39
-
-
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
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") | |
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