Skip to content

Instantly share code, notes, and snippets.

@FarshidRoohi
Created February 28, 2020 15:38
Show Gist options
  • Save FarshidRoohi/a660556888489cd1e486de3246cbee7f to your computer and use it in GitHub Desktop.
Save FarshidRoohi/a660556888489cd1e486de3246cbee7f to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@ObservedObject var myViewModel = MyViewModel()
var body: some View {
ScrollView {
VStack {
ForEach(self.myViewModel.items.indices , id : \.self) {index in
RowForTest(item: self.myViewModel.items[index])
}
Button(action: {
print(self.myViewModel.items[0].value)
}){
Text("Submit")
}.padding()
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct RowForTest: View {
@State var item :MyModel
var body: some View {
HStack {
Text(item.title)
TextField("enter value", text: Binding(get: {
return self.item.value
}, set: { newValue in
self.item.value = newValue
}))
}.padding()
}
}
@AvinashRamireddy31
Copy link

Really helpful to start with

But what if I have multiple textfields(name, value, oneLinedescription) in each row of list? Should I create 3 variables in RowForTest for write or is there any better way to pass entire object for write?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment