Instance Method


Returns the property identified by a given key.


- (id)storedValueForKey:(NSString *)key;


This method is used when the value is retrieved for storage in an object store (generally, this storage is ultimately in a database) or for inclusion in a snapshot. The default implementation is similar to the implementation of valueForKey:, 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”, storedValueForKey: looks for a method named _getLastName or _lastName.

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

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

  4. If key is unknown, storedValueForKey: calls handleTakeValue:forUnboundKey:.

This different search order allows an object to bypass processing that is performed before returning a value through a public API. However, if you always want to use the search order in valueForKey:, 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

+ useStoredAccessor

Returns YES if the stored value methods storedValueForKey: and takeStoredValue:forKey: should use private accessor methods in preference to public accessors.

- handleQueryWithUnboundKey:

Invoked by valueForKey: when it finds no property corresponding to key.

- handleTakeValue:forUnboundKey:

Invoked by takeValue:forKey: when it finds no property binding for key.

- takeStoredValue:forKey:

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

- takeValuesFromDictionary:

Sets properties of the receiver with values from a given dictionary, using its keys to identify the properties

- takeValue:forKeyPath:

Sets the value for the property identified by keyPath to value.

- takeValue:forKey:

Sets the value for the property identified by key to value.

- unableToSetNilForKey:

Invoked if key is represented by a scalar attribute.

- valuesForKeys:

Returns a dictionary containing as keys the property names in keys, with corresponding values being the corresponding property values.