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 ?