0

I have a little problem,

I have a Swift app with a picker:

/// DATA.swift

import SwiftUI

class FormPage: ObservableObject { 
    @State var country = ["USA", "Japan", "Germany"]
    @State var index = 0
}

/// FORM.swift

import SwiftUI

struct ContentView: View {
    
    @StateObject var choiceForm = FormForFormulaire()
    
    var body: some View {
        
        Form {
            Section {
                Picker(selection: $choiceForm.index, label: Text("Pays de destination")) {
                    ForEach(0 ..< choice.country.count) {
                        Text(choiceForm.country[$0]).tag($0)
                    }
                }
            }
        }

The picker view is working but it doesn't update: I click Japan, and the view doesn't change.

Sorry for my English, I hope someone understood me!!

Thanks

1 Answer 1

2

Use @Published for index inside the FormPage class

@Published var index = 0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.