The default implementation of the key-value coding protocol methods provided by ​​NSObject​​ work with both object and non-object properties. The default implementation automatically translates between object parameters or return values, and non-object properties. This allows the signatures of the key-based getters and setters to remain consistent even when the stored property is a scalar or a structure.



NOTE

Because all properties in Swift are objects, this section only apples to Objective-C properties.


When you invoke one of the protocol’s getters, such as ​​valueForKey:​​, the default implementation determines the particular accessor method or instance variable that supplies the value for the specified key according to the rules described in ​​Accessor Search Patterns​​. If the return value is not an object, the getter uses this value to initialize an ​​NSNumber​​ object (for scalars) or ​​NSValue​​ object (for structures) and returns that instead.

Similarly, by default, setters like ​​setValue:forKey:​​ determine the data type required by a property’s accessor or instance variable, given a particular key. If the data type is not an object, the setter first sends an appropriate ​​<type>Value​​ message to the incoming value object to extract the underlying data, and stores that instead.


------------------越是喧嚣的世界,越需要宁静的思考------------------ 合抱之木,生于毫末;九层之台,起于垒土;千里之行,始于足下。 积土成山,风雨兴焉;积水成渊,蛟龙生焉;积善成德,而神明自得,圣心备焉。故不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。蚓无爪牙之利,筋骨之强,上食埃土,下饮黄泉,用心一也。蟹六跪而二螯,非蛇鳝之穴无可寄托者,用心躁也。