Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding if a class is key-value-compliant for a given key

Is there a method to find out if a class is key-value-compliant for a given key?

like image 896
cfischer Avatar asked Dec 12 '22 21:12

cfischer


1 Answers

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.

like image 121
Grady Player Avatar answered Apr 28 '23 15:04

Grady Player