was sent to an object that is not KVC-compliant for the "com" property

Viewed 1951

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)

I then implemented this:

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

}

When I run the app observeValue... is never called when that default is changed, instead Xcode crashes with this error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ addObserver: forKeyPath:@"com.apple.configuration.managed" options:1 context:0x0] was sent to an object that is not KVC-compliant for the "com" property.'

What's the right way of observing com.apple.configuration.managed in the UserDefaults.standard?

1 Answers
Related