[Accessor Search Implementation Details]

  Key-value coding attempts to use accessor methods to get and set values, before resorting to directly accessing the instance variable.

  Key-value coding 优先使用accessor methods走获取与设置数据,之后再使直接访问instance variable.

[Accessor Search Patterns for Simple Attributes]  

Default Search Pattern for setValue:forKey:

When the default implementation of setValue:forKey: is invoked for a property the following search pattern is used:

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

  2. 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.

  3. If a matching accessor or instance variable is located, it is used to set the value.

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

Default Search Pattern for valueForKey:

When the default implementation of valueForKey: is invoked on a receiver, the following search pattern is used:

  1. Searches the class of the receiver for an accessor method whose name matches the pattern get<Key><key>, or is<Key>, in that order. If such a method is found it is invoked.

  2. Otherwise (no simple accessor method is found), searches the class of the receiver for methods whose names match the patterns countOf<Key> and objectIn<Key>AtIndex: (corresponding to the primitive methods defined by the NSArray class) and <key>AtIndexes: (corresponding to the NSArraymethod objectsAtIndexes:).

    If the countOf<Key> method and at least one of the other two possible methods are found, a collection proxy object that responds to all NSArray methods is returned. Each NSArray message sent to the collection proxy object will result in some combination of countOf<Key>objectIn<Key>AtIndex:, and<key>AtIndexes: messages being sent to the original receiver of valueForKey:. If the class of the receiver also implements an optional method whose name matches the pattern get<Key>:range: that method will be used when appropriate for best performance.

  3. Otherwise (no simple accessor method or set of array access methods is found), searches the class of the receiver for a threesome of methods whose names match the patterns countOf<Key>enumeratorOf<Key>, and memberOf<Key>: (corresponding to the primitive methods defined by the NSSet class).

    If all three methods are found, a collection proxy object that responds to all NSSet methods is returned. Each NSSet message sent to the collection proxy object will result in some combination of countOf<Key>enumeratorOf<Key>, and memberOf<Key>: messages being sent to the original receiver ofvalueForKey:.

  4. Otherwise (no simple accessor method or set of collection access methods is found), if the receiver's class method accessInstanceVariablesDirectlyreturns YES, the class of the receiver is searched for an instance variable whose name matches the pattern _<key>_is<Key><key>, or is<Key>, in that order. If such an instance variable is found, the value of the instance variable in the receiver is returned. If the type of the result is one of the scalar types supported by NSNumber conversion is done and an NSNumber is returned. Otherwise, conversion is done and an NSValue is returned. Results of arbitrary types are converted to NSValue objects, not just NSPointNSRangeNSRect, and NSSize types.

  5. If none of the above situations occurs, returns a result the default implementation invokes valueForUndefinedKey:.

更多资料参考: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/SearchImplementation.html

Accessor Search Implementation Details的更多相关文章

  1. 17.2.1 Replication Implementation Details 复制实现细节:

    17.2 Replication Implementation 复制是基于master server 跟踪所有改变到他的数据库(更新,删除等等)在它的binary log. binary log 作为 ...

  2. [Angular] Extract Implementation Details of ngrx from an Angular Application with the Facade Pattern

    Extracting away the implementation details of ngrx from your components using the facade pattern cre ...

  3. The implementation details of the built thermal setup

    Lucid infrared thermography of thermally-constrained processors

  4. iOS修改声明为readonly的属性值

    本文讨论的是,对于类中声明为 readonly 的属性值,我们就不可以修改其值了么?如何可以,那么如何修改呢? 为了便于说明,定义一个 ACLStudent 的类: ACLStudent.h @int ...

  5. 论文笔记:Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation

    Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation2019-03-18 14:4 ...

  6. (转)The Evolved Transformer - Enhancing Transformer with Neural Architecture Search

    The Evolved Transformer - Enhancing Transformer with Neural Architecture Search 2019-03-26 19:14:33 ...

  7. Foundation: Binary Search

    /* Binary search. * * Implementation history: * 2013-10-5, Mars Fu, first version. */ /* [Binary Sea ...

  8. 17.2?Replication Implementation 复制实施:

    17.2?Replication Implementation 复制实施: 17.2.1 Replication Implementation Details 17.2.2 Replication R ...

  9. [转]An overview of Openvswitch implementation

    This is NOT a tutorial on how to use openvswitch, this is for developers who want to know the implem ...

随机推荐

  1. ERROR 1442 (HY000):because it is already used by statement which invoked this stored function/tr

    看到mysql的触发器,随手写了一个: mysql> create trigger t_ai_test -> after insert on test -> for each row ...

  2. core--线程同步(用户模式)

    用户模式下的多线程同步只适用用于同一个进程内的多个线程,其范围使用于读写问题:比如一本书,必须是作者A写完之后,读者B才能够读取.否则作者一边修改,读者一边读,完全乱套. 线程读者B如何能在多线程环境 ...

  3. NuGet的安装;

        下载完毕安装需要重启一下VS 然后我们去NuGet里面安装我们要的客户端 搜索  CouchbaseNetClient   引用之后,编译项目,查看到已引用的dll文件

  4. == Rickard Oberg & TheServerSide

    看了Hani Suleiman和Rickard Oberg ,发现其实每个所谓的权威都应该有被质疑的绝对,可能往往权威会令人觉得理所应当

  5. SkinPP for VC

    1.下载文件:SkinPPWTL.h,SkinPPWTL.dll,SkinPPWTL.lib以及Skin++皮肤库: 2.新建一个工程,如:基于多文档的工程,名为:MySkin: 3.将下载的Skin ...

  6. html元素中class属性值多个空格分格

    问题: 比如 <div class="alert alert-info"> 回答: 同时指定了多个CSS样式,这里面的alert-info还可以换成alert-warn ...

  7. C++ STL知识点小结

    1.capacity(容量)与size(长度)的区别. size(长度)指容器当前拥有的元素个数. capacity(容量)指容器在必须分配新存储空间之前可以存储的元素总数.

  8. 【Mongo】MongoVUE的使用

    我一直是在终端操作的mongo,各种update set remove insert,后来查了下有个叫mongoVUE的客户端,界面化比较方便操作吧~ 网上搜了下,说MongoVUE已经n年没有更新了 ...

  9. Linux基本命令(6)线上查询的命令

    线上查询的命令 命令 功能 man 查询和解释一个命令的使用方法,以及这个命令的说明事项 locate 定位文件和目录 whatis 寻找某个命令的含义 6.1 man命令 man命令用来查询和解释一 ...

  10. jQuery 关于ScrollableGridPlugin.js(固定表头)插件的逐步解析

    以前写前台的时候需要用哪些效果从来都是有现成的东西拿来就用的,因为自己真的是有些懒,毫无探索精神,只重视结果,不追求过程. 这个ScrollableGridPlugin.js是从网上找到的一个具有固定 ...