From the Landmarks sample project, I tried a variation, to get two cells side by side in the List.
This is the original with on cell per row as in the tutorial:
Surprisingly, the following variation works well to display 2 cells side by side:
I thus tried to go on and add navigationLinks…
It works when adding a navigation link to the first cell only
But adding NavigationLink to the second makes it fail:
The error is on line 3:
Or did I miss something ?
Which expression could I break ?
This is the original with on cell per row as in the tutorial:
Code Block struct LandmarkList: View { var body: some View { List(landmarks) { landmark in LandmarkRow(landmark: landmark) } } }
Surprisingly, the following variation works well to display 2 cells side by side:
Code Block struct LandmarkList: View { var body: some View { List (0 ..< (landmarks.count+1)/2) { item in LandmarkRow(landmark: landmarks[2*item]) if 2*item + 1 < landmarks.count { LandmarkRow(landmark: landmarks[(2*item)+1]) } } } }
I thus tried to go on and add navigationLinks…
It works when adding a navigation link to the first cell only
Code Block struct LandmarkList: View { var body: some View { NavigationView { List (0 ..< (landmarks.count+1)/2) { item in NavigationLink(destination: LandmarkDetail()) { LandmarkRow(landmark: landmarks[2*item]) } if 2*item + 1 < landmarks.count { LandmarkRow(landmark: landmarks[(2*item)+1]) } } .navigationTitle("Landmarks") } } }
But adding NavigationLink to the second makes it fail:
Code Block struct LandmarkList: View { var body: some View { NavigationView { List (0 ..< (landmarks.count+1)/2) { item in NavigationLink(destination: LandmarkDetail()) { LandmarkRow(landmark: landmarks[2*item]) } if 2*item + 1 < landmarks.count { NavigationLink(destination: LandmarkDetail()) { LandmarkRow(landmark: landmarks[(2*item)+1]) } } } .navigationTitle("Landmarks") } } }
The error is on line 3:
Is it a normal List behaviour ?The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions
Or did I miss something ?
Which expression could I break ?
Thanks for the hint.
id: \.self was missing here.
In addition, I had to specify the landmark.
This does "work", at least compile and run
However, when I activate a link, I get the behaviour you described:
SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug.
What I did: Dec 31, 2020 at 9:11 PM – FB8958299
id: \.self was missing here.
In addition, I had to specify the landmark.
This does "work", at least compile and run
Code Block List (0 ..< (landmarks.count+1)/2, id: \.self) { item in NavigationLink(destination: LandmarkDetail(landmark: landmarks[2*item])) { LandmarkRow(landmark: landmarks[2*item]) } if 2*item + 1 < landmarks.count { NavigationLink(destination: LandmarkDetail(landmark: landmarks[(2*item)+1])) { LandmarkRow(landmark: landmarks[(2*item)+1]) } } }
However, when I activate a link, I get the behaviour you described:
links to the first item in row
links to second item automatically.
SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug.
What I did: Dec 31, 2020 at 9:11 PM – FB8958299