Finding if a class is key-value-compliant for a given key
-
14-07-2021 - |
Question
Is there a method to find out if a class is key-value-compliant for a given key?
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow