Was sent to an object that does not meet the KVC requirements for the property "com"

I want to observe the value stored in UserDefaults.standard under the key: com.apple.configuration.managed , so I did this:

UserDefaults.standard.addObserver(self, forKeyPath: "com.apple.configuration.managed", options: [.new, .old], context: nil)

Then I implemented this:

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

}

When I start the watchValue application ... it is never called when this default value is changed, instead, Xcode crashes this error:

*** Application termination due to an uncaught exception "NSUnknownKeyException", reason: "[addObserver: forKeyPath: @" com.apple.configuration.managed "options: 1 context: 0x0] was sent to an object that does not meet the KVC requirements for" com ', Property'.

com.apple.configuration.managed UserDefaults.standard?

+4
1

KVC , KVC- , UserDefaults, KVC , , .

, , UserDefaults KVC com; , , , managed , configuration , apple , com com t20 > .

, KVC , "MyDefault", "My.Default". , NSUserDefaultsDidChangeNotification Notification

+2

Source: https://habr.com/ru/post/1682350/


All Articles