Get error `NSUbiquitousKeyValueStore` this class is not key value coding-compliant for the key

675 views Asked by At

I'm trying to use iCloud key-value using NSUbiquitousKeyValueStore class. But when I try to get value by specified key, I get an error

[<NSUbiquitousKeyValueStore 0x6000002983d0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key "some_key"

How can I solve this?

2

There are 2 answers

0
vomi On

Use:

NSUbiquitousKeyValueStore.default.set(yourValue, forKey: "your.key")

instead of

NSUbiquitousKeyValueStore.default.setValue(yourValue, forKey: "your.key")

0
CodenameDuchess On

It's possible you're getting this error if the value you're trying to store is not exposed to the objective-c runtime (like an optional value type for instance). Try converting your Int/Double/etc to a non-optional NSNumber and then retrieving it via object(forKey:) instead.