SwiftUI: How to iterate over an array of bindable objects?

后端 未结 4 1004
一生所求
一生所求 2021-02-05 14:51

I\'m trying to learn SwiftUI, and how bindings work.

I have this code that works, that shows a list of projects. When one project is tapped, a binding to that project is

4条回答
  •  猫巷女王i
    2021-02-05 15:29

    Unfortunately this doesn't seem to be possible at this time. The only way to achieve this is like the following:

    ForEach(state.projects.indices) { index in
        NavigationLink(destination: ProjectView(project: state.projects[index])) {
            Text(state.projects[index].title)
        }
    } 
    

    NOTE: I didn't compile this code. This is just to give you the gesture for how to go about it. i.e. use and index of type Index and not Int.

提交回复
热议问题