---
title: "setValue(_:forKeyPath:)"
framework: objectivec
role: symbol
role_heading: Instance Method
path: "objectivec/nsobject-swift.class/setvalue(_:forkeypath:)"
---

# setValue(_:forKeyPath:)

Sets the value for the property identified by a given key path to a given value.

## Declaration

```swift
func setValue(_ value: Any?, forKeyPath keyPath: String)
```

## Parameters

- `value`: The value for the property identified by keyPath.
- `keyPath`: A key path of the form relationship.property (with one or more relationships): for example “department.name” or “department.manager.lastName.”

## Discussion

Discussion The default implementation of this method gets the destination object for each relationship using value(forKey:), and sends the final object a setValue(_:forKey:) message. Special Considerations When using this method, and the destination object does not implement an accessor for the value, the default behavior is for that object to retain value rather than copy or assign value.

## See Also

### Related Documentation

- [value(forKeyPath:)](objectivec/nsobject-swift.class/value(forkeypath:).md)

### Setting Values

- [setValuesForKeys(_:)](objectivec/nsobject-swift.class/setvaluesforkeys(_:).md)
- [setNilValueForKey(_:)](objectivec/nsobject-swift.class/setnilvalueforkey(_:).md)
- [setValue(_:forKey:)](objectivec/nsobject-swift.class/setvalue(_:forkey:).md)
- [setValue(_:forUndefinedKey:)](objectivec/nsobject-swift.class/setvalue(_:forundefinedkey:).md)
