---
title: "takeStoredValue(_:forKey:)"
framework: objectivec
role: symbol
role_heading: Instance Method
path: "objectivec/nsobject-swift.class/takestoredvalue(_:forkey:)"
---

# takeStoredValue(_:forKey:)

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

## Declaration

```swift
func takeStoredValue(_ value: Any?, forKey key: String)
```

## Discussion

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: 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:. 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. 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:. 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 value(forKey:), you can prevent direct access of an instance variable with the class method accessInstanceVariablesDirectly.

## See Also

### Deprecated Methods

- [accessibilityAttributeNames()](objectivec/nsobject-swift.class/accessibilityattributenames().md)
- [accessibilityAttributeValue(_:)](objectivec/nsobject-swift.class/accessibilityattributevalue(_:).md)
- [accessibilityAttributeValue(_:forParameter:)](objectivec/nsobject-swift.class/accessibilityattributevalue(_:forparameter:).md)
- [accessibilityActionDescription(_:)](objectivec/nsobject-swift.class/accessibilityactiondescription(_:).md)
- [accessibilityActionNames()](objectivec/nsobject-swift.class/accessibilityactionnames().md)
- [accessibilityArrayAttributeCount(_:)](objectivec/nsobject-swift.class/accessibilityarrayattributecount(_:).md)
- [accessibilityArrayAttributeValues(_:index:maxCount:)](objectivec/nsobject-swift.class/accessibilityarrayattributevalues(_:index:maxcount:).md)
- [accessibilityIndex(ofChild:)](objectivec/nsobject-swift.class/accessibilityindex(ofchild:).md)
- [accessibilityIsAttributeSettable(_:)](objectivec/nsobject-swift.class/accessibilityisattributesettable(_:).md)
- [accessibilityIsIgnored()](objectivec/nsobject-swift.class/accessibilityisignored().md)
- [accessibilityParameterizedAttributeNames()](objectivec/nsobject-swift.class/accessibilityparameterizedattributenames().md)
- [accessibilityPerformAction(_:)](objectivec/nsobject-swift.class/accessibilityperformaction(_:).md)
- [accessibilitySetOverrideValue(_:forAttribute:)](objectivec/nsobject-swift.class/accessibilitysetoverridevalue(_:forattribute:).md)
- [accessibilitySetValue(_:forAttribute:)](objectivec/nsobject-swift.class/accessibilitysetvalue(_:forattribute:).md)
- [fileManager(_:shouldProceedAfterError:)](objectivec/nsobject-swift.class/filemanager(_:shouldproceedaftererror:).md)
