BLACK FRIDAY: Save 50% on all my Swift books and bundles! >>

Textfield and array

Forums > 100 Days of SwiftUI

I am trying to solve challange 35

i want to use a textField for the answer but if i put a $answer as soon as i hit the first answer it copies in al the answers, i tried $answer[index] but does not throw an error but the app crash.

this code is only for trying to solve that problem

import SwiftUI

struct QuestionsRow: View {
    @State private var answer = [""]
    var body: some View {
        ScrollView {
            ForEach(0 ..< 5, id:\.self) { index in
                HStack {
                    Text("5 X \(index) =")

                    TextField("0", text: self.$answer[index])
                }
            }
        }
    }
}

struct QuestionsRow_Previews: PreviewProvider {
    static var previews: some View {
        QuestionsRow()
    }
}

3      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.