iOS学习笔记4-KVC底层原理

Key-Value Coding 键值编码app

setValuesForKeysWithDictionary 调用顺序:编码

循环遍历字典中的全部key,并调用setValue: forKey: 方法spa

* 若是key存在,设置数值orm

* 若是key不存在,调用 setValue:forUndefinedKey: 方法 (默认奔溃)文档

官方文档说明:get

The receiver’s class is searched for an accessor method whose name matches the pattern set<Key>:it

If no accessor is found, and the receiver’s class method accessInstanceVariablesDirectly returns YES, the receiver is searched for an instance variable whose name matches the pattern _<key>, _is<Key>, <key>, or is<Key>, in that order.io

If a matching accessor or instance variable is located, it is used to set the value. If necessary, the value is extracted from the object as described in Representing Non-Object Values.class

If no appropriate accessor or instance variable is found, setValue:forUndefinedKey: is invoked for the receiver.sed

setValue:forKey: 调用顺序

一、寻找set<Key>:方法

二、没有找到set<Key>:方法,就按照_<key>, _is<Key>, <key>, is<Key> 顺序寻找

三、若是尚未找到,就调用 setValue:forUndefinedKey: 方法(默认崩溃)

valueForKey: 调用循序

一、按照get<Key>, <key>, is<Key>顺序寻找

二、若是没有找到,就按照_<key>, _is<Key>, <key>, is<Key>顺序寻找

三、若是尚未找到,就调用 valueForUndefinedKey: 方法(默认崩溃)

相关文章
相关标签/搜索