---
title: "anchorPreference(key:value:transform:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/anchorpreference(key:value:transform:)"
---

# anchorPreference(key:value:transform:)

Sets a value for the specified preference key, the value is a function of a geometry value tied to the current coordinate space, allowing readers of the value to convert the geometry to their local coordinates.

## Declaration

```swift
nonisolated func anchorPreference<A, K>(key _: K.Type = K.self, value: Anchor<A>.Source, transform: @escaping (Anchor<A>) -> K.Value) -> some View where K : PreferenceKey

```

## Parameters

- `key`: The preference key type.
- `value`: The geometry value in the current coordinate space.
- `transform`: The function to produce the preference value.

## Return Value

Return Value A new version of the view that writes the preference.

## See Also

### Setting preferences based on geometry

- [transformAnchorPreference(key:value:transform:)](swiftui/view/transformanchorpreference(key:value:transform:).md)
