---
title: "setValue(forKey:to:)"
framework: swiftdata
role: symbol
role_heading: Instance Method
path: "swiftdata/backingdata/setvalue(forkey:to:)-2idfg"
---

# setValue(forKey:to:)

## Declaration

```swift
func setValue<Value, OtherModel>(forKey: KeyPath<Self.Model, Value>, to newValue: Value) where Value : Encodable, Value : RelationshipCollection, OtherModel == Value.PersistentElement
```
