0

this is my code! I want to complete this code and when I tapped on button the values of two selections start changing..

  import SwiftUI

struct Container {
    var one: String
    var two: String
}

struct ContentView: View {
    @State  var container: Container
    @State  var list = ["1","2","3","4","5","6","7","8","9"]
    var body: some View {
        Picker("Select",selection: $container.one) {
            ForEach(list, id: \.self) { item in
                Text(item)
            }
        }
        .pickerStyle(.menu)
        Picker("Select",selection: $container.two) {
            ForEach(list, id: \.self) { item in
                Text(item)
            }
        }
        .pickerStyle(.menu)
        
    }
}
0

1 Answer 1

1

I found the solution with tuples using this button :

Button {
            (container.one , container.two) = (container.two , container.one)
        }label: {
            Image(systemName: "plus")
        }

Not the answer you're looking for? Browse other questions tagged or ask your own question.