How should I properly set up to receive notifications when the variable changes on the shared instance of the singleton? Currently, the block is never fired.
class MyViewController: UIViewController {
private var observer: NSKeyValueObservation?
func configureKVO() {
observer = MySingleton.shared.observe(\.shouldFetchDataFromServer) { (manager, change) in
print("Changed: \(manager.shouldFetchDataFromServer)")
}
MySingleton.shared.shouldFetchDataFromServer = false
MySingleton.shared.shouldFetchDataFromServer = true
}
}
class MySingleton: NSObject {
static let shared = MySingleton()
@objc var shouldFetchDataFromServer: Bool = false
}