---
title: "overlayPreferenceValue(_:_:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/overlaypreferencevalue(_:_:)"
---

# overlayPreferenceValue(_:_:)

Reads the specified preference value from the view, using it to produce a second view that is applied as an overlay to the original view.

## Declaration

```swift
nonisolated func overlayPreferenceValue<Key, T>(_ key: Key.Type = Key.self, @ContentBuilder _ transform: @escaping (Key.Value) -> T) -> some View where Key : PreferenceKey, T : View

```

## Parameters

- `key`: The preference key type whose value is to be read.
- `transform`: A function that produces the overlay view from the preference value read from the original view.

## Return Value

Return Value A view that layers a second view in front of the view.

## See Also

### Generating backgrounds and overlays from preferences

- [backgroundPreferenceValue(_:_:)](swiftui/view/backgroundpreferencevalue(_:_:).md)
- [backgroundPreferenceValue(_:alignment:_:)](swiftui/view/backgroundpreferencevalue(_:alignment:_:).md)
- [overlayPreferenceValue(_:alignment:_:)](swiftui/view/overlaypreferencevalue(_:alignment:_:).md)
