Instance Method インスタンスメソッド

takeStoredValue:forKey:

Sets the value of the property identified by a given key.

Declaration 宣言

- (void)takeStoredValue:(id)value 
                 forKey:(NSString *)key;

Discussion 解説

This method is used to initialize the receiver with values from an object store (generally, this storage is ultimately from a database) or to restore a value from a snapshot. The default implementation is similar to the implementation of takeValue:forKey:, but it resolves key with a different method/instance variable search order:

  1. Searches for a private accessor method based on key (a method preceded by an underbar). For example, with a key of “lastName”, takeStoredValue:forKey: looks for a method named _setLastName:.

  2. If a private accessor is not found, searches for an instance variable based on key and sets its value directly. For example, with a key of “lastName”, takeStoredValue:forKey: looks for an instance variable named _lastName or lastName.

  3. If neither a private accessor nor an instance variable is found, takeStoredValue:forKey: searches for a public accessor method based on key. For the key “lastName”, this would be setLastName:.

  4. If key is unknown, takeStoredValue:forKey: calls handleTakeValue:forUnboundKey:.

This different search order allows an object to bypass processing that is performed before setting a value through a public API. However, if you always want to use the search order in takeValue:forKey:, you can implement the class method useStoredAccessor to return NO. And as with valueForKey:, you can prevent direct access of an instance variable with the class method accessInstanceVariablesDirectly.

See Also 参照

Deprecated Methods 非推奨メソッド