The Foundation Framework defines NSObject (nskeyvaluecoding),
-(void) SetValue: (ID) value Forkey: (NSString *) key;
Description of the interface
1. Search for method-set<key> in the class of message receiver first:
2. If not found in 1, search for _<key> in class, _is<key>, <key>, is<key> instance variable
3. If not found in 2, call method-setvalue:forundefinedkey:, and the default implementation of the method is to throw
Exception nsundefinedkeyexception
The next question, then, in the iOS SDK, so many frameworks, so many classes, then which class covers the NSObject
What about the default implementation of-setvalue:forundefinedkey:?
1 IMP animationimp = [caanimation instancemethodforselector: @selector (setvalue:forundefinedkey:)]; 2 3 IMP defaultimp = [nsobject instancemethodforselector: @selector (setvalue:forundefinedkey:)]; 4 5 IMP viewimp = [UIView instancemethodforselector: @selector (setvalue:forundefinedkey:)]; 6 7 NSLog (@ "defaultimp:%p, Animationimp:%p, Viewimp:%p", Defaultimp, Animationimp, Viewimp);
The output of log is: defaultimp:0x125dc84, ANIMATIONIMP:0X10D5CA, viewimp:0x125dc84
Visible UIView does not overwrite the default implementation of NSObject, which is the same class and NSObject classes that match the return values of the following calls
So when using-setvalue:forkey: You need to use Try-catch to wrap the call to this method.
IOS.KVC.setValue:forKey: