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: 方法(默認崩潰)

相關文章
相關標籤/搜索