zoukankan      html  css  js  c++  java
  • Accessor Search Implementation Details

    [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

  • 相关阅读:
    spring boot 在windows下安装为service(转)
    win7安装Anaconda+TensorFlow+配置PyCharm(转)
    IDEA中Spring boot配置热部署无效问题解决方式(转)
    WEB后台--基于Token的WEB后台登录认证机制(转)
    selenium之使用chrome浏览器测试(附chromedriver与chrome的对应关系表)(转)
    开源巨献:Google最热门60款开源项目(转)
    反射获取一个方法中的参数名(不是类型)(转)
    ELK原理与介绍(转)
    Linux下Redis的安装和部署(转)
    webpack+ES6+less开发环境搭建(转)
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3587034.html
Copyright © 2011-2022 走看看