Group Group Group Group Group Group Group Group Group

Your Second iOS and SwiftUI App · Binding | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5662524-your-second-ios-and-swiftui-app/lessons/20

I found I can just use the code below to add task and edit task successfully, without using the ForEach.swift and IndexedCollection.swift.

List {
ForEach(Array(taskVM.tasks.enumerated()), id: .1.id) { index, task in
RowView(task: self.$taskVM.tasks[index])
}

}

1 Like

I just tried it again, both in this version of the project, and the final one. It works!

But it didn’t work when I was writing this course. :disappointed: Next year, hopefully this will be stable and we’ll get to employ it, or something newer and simpler!

For reference, if anyone else wants to try out the code without renaming:

ForEach(
  Array( taskStore.tasks.enumerated() ),
  id: \.element.id
) { index, _ in
  RowView(task: self.$taskStore.tasks[index])
}

I just tried that in my project and it worked. Cool!

I got the app to crash with the extension added: Fatal error: Index out of range
I played a little bit around removing, moving and editing. When I came down to 2 or 3 items it crashed…

I’m experiencing the same range exception as qmlearner2011 when deleting from a small list (1-3 items). Things work pretty well with or without the extension…except for that crash.

I had this problem as well. Switching to the enumerated array code worked for me.

Thanks in advance for your patience…

In this tutorial, it seems that the NavigationLink is used to get to an editable mode. In my app, NavigationLink is used to navigate to a child entity of the parent: From a House to a Room in the House for example. I then want to edit the attributes of the room. I wanted to use a conditional based on if I was in editing mode to determine the view I get to. Take me from the House to the list of rooms if I am not in edit mode, but take me to the EditHouseView if I am in edit mode. But no examples seem to be doing that. I am a 2 year old newbie and just want to finish my app lol… The only thing I can not get to work is updating my entities. How do I present the editRoomView if I am using the navigation links to navigate my data model… I have learned a ton from you all, thanks. I am just missing what I need to finish the app…

NavigationLink(destination: isEditing ?? EditPropertyView(property: property) : PropertyDetailView(property: property)){
PropertyRowView(property: property)
}

Am I not supposed to use the navigation link to traverse relationships between entities?
Is edit mode just for deleting objects and not editing them?

So far, SwiftUI seems to offer no way to do what you want to do. :slightly_frowning_face: (Discussion in the comments for the Edit Mode episode.) Instead, I think you’ll need to rely on another switching mechanism than the Edit Mode button.