Is there a method to find out if a class is key-value-compliant for a given key?
Asked
Active
Viewed 1,776 times
6
-
Did you figure out an answer to this better that the one from Grady Player? As you can see, DanSkeel believes the answer isn't completely reliable. – daniel Oct 01 '22 at 03:05
1 Answers
13
you can ask if it responds to the selector, or ask for the value for key
//will check for the getter
[anObj respondsToSelector:@selector(someKey)]
//will check in a way that doesn't throw an exception for a value
[andObj valueForKey:@"someKey"]
//keypath of a nested value
[anObj valueForKeypath:@"child.property"]
but if you are getting a message that something isn't KVC compliant that usually means you have set something up incorrectly, a binding with the wrong key or class for instance.

Grady Player
- 14,399
- 2
- 48
- 76
-
-
@rockey No it's not. Object can be key value coding-compliant for `somekey` but your method call will return `NO`. – DanSkeel Jan 21 '15 at 19:31