This is my code:
import SwiftUI
struct VPickerView<T: Hashable>: View {
    private let elements: [T]
    private let selection: Binding<T>
    
    init(elements: [T], selection: Binding<T>) {
        self.elements = elements
        self.selection = selection
    }
    
    var body: some View {
        HStack(spacing: 5) {
            ZStack {
                Color.green
                    .frame(width: 45, height: 30)
                    .cornerRadius(15)
                Picker("", selection: $selection) { // Cannot find '$selection' in scope
                    ForEach(elements, id: \.self) {
                        Text(String($0))
                            .font(.title)
                            .foregroundColor($0 == selection as! T ? .blue : .red)
                    }
                }.onChange(of: selection) { _ in
                    print("changed")
                }
                .labelsHidden()
                .pickerStyle(.wheel)
                .border(.black, width: 5)
                .frame(width: 55)
            }
        }
    }
}
But I receive an error Cannot find '$selection' in scope and I don't know why.
How do I want to use it?
private let hours: [Int]
@State private var selectedHour: Int = 0
var body: some View {
    VPickerView(elements: hours, selection: $selectedHour)
}
Conditions:
- selected element should be blue, otherwise red.
- type of elements might be Int, Double, String, Int64


self._selection = selectionit will work. To make it work now just remove the$it is already aBindingyou don't need it but you will have UI update issues, you need the@Binding