- (nullable id)valueForKey:(NSString *)key;
- (void)setValue:(nullable id)value forKey:(NSString *)key;
- (nullable id)valueForKeyPath:(NSString *)keyPath;
- (void)setValue:(nullable id)value forKeyPath:(NSString *)keyPath;
forKeyPath:和forKey:不同之处在于,forKeyPath可以@"对象.属性.属性",例如:@"person.dog.name";
🌟setValue:forKey:先按setKey:,_setKey:顺序查找方法
没找到查看accessInstanceVariablesDirectly的返回值如果为NO抛出异常
如果为YES按照_key,_isKey, key, isKey 顺序查找成员变量找到直接赋值
没找到抛出异常
🌟 accessInstanceVariablesDirectly默认返回YES
Screen Shot 2020-04-13 at 7.48.12 PM.png
🌟valueForKey:先按getKey,key,isKey,_key,顺序查找方法
没找到查看accessInstanceVariablesDirectly的返回值如果为NO抛出异常
如果为YES按照_key,_isKey, key, isKey 顺序查找成员变量找到直接取值
没找到抛出异常
网友评论