projectedValue
A projection of the binding value that returns a binding.
Declaration
var projectedValue: Binding<Value> { get }Discussion
Use the projected value to pass a binding value down a view hierarchy. To get the projectedValue, prefix the property variable with $. For example, in the following code example PlayerView projects a binding of the state property isPlaying to the PlayButton view using $isPlaying.
struct PlayerView: View {
var episode: Episode
@State private var isPlaying: Bool = false
var body: some View {
VStack {
Text(episode.title)
.foregroundStyle(isPlaying ? .primary : .secondary)
PlayButton(isPlaying: $isPlaying)
}
}
}