问题
Currently showing specific routines by authenticated users. I want to be able to edit routines. However, the current app is crashing when I try to edit. Any help would be appreciated! Please let me know if it would be helpful for me to add more information.
My main View:
struct custView: View {
@ObservedObject var viewModel = RoutinesViewModel()
var body: some View {
List {
ForEach(viewModel.routines, id: \.self) { routine in
HStack {
Text(routine.routine)
NavigationLink(destination: Modify(id: routine.id)) {
Text("")
}
}
}
}
}
}
Code to modify routine:
struct Modify: View {
@State var txt = ""
var id = ""
var body: some View {
VStack {
TextField("Edit", text: $txt).textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: {
let db = Firestore.firestore().collection("routines")
db.document(self.id).updateData(["routine": self.txt]) { (err) in
if err != nil {
print((err?.localizedDescription)!)
return
}
print("success")
}
}) {
Text("Modify")
}
}
}
}
See below for my database structure.

来源:https://stackoverflow.com/questions/62274356/swiftui-firebase-not-able-to-edit-row