Hi,
I'm trying to show a number of buttons of a certain relative size to the screen width. For now I'm hard-coding the number of buttons, just to get the collection view wrap style working.
I'm getting the Xcode error:
It worked fine, compiled, and ran in preview mode a couple of times. Then with no changes it just stopped compiling, and Xcode gave the error.
Any suggestions as to what can I do? Eventually I want to use the index calculation to subscript an array value.
I'm trying to show a number of buttons of a certain relative size to the screen width. For now I'm hard-coding the number of buttons, just to get the collection view wrap style working.
I'm getting the Xcode error:
It seems obvious that doing the indexing calculations probably cause the problem. But I don't know how to do that calculation once per iteration, and store the value.The compiler is unable to type-check this expression in reasonable time
It worked fine, compiled, and ran in preview mode a couple of times. Then with no changes it just stopped compiling, and Xcode gave the error.
Any suggestions as to what can I do? Eventually I want to use the index calculation to subscript an array value.
Code Block struct collectionView: View { let totalElements = 5 let rowCount = 2 let rowLength = 3 var body: some View { GeometryReader<AnyView> { geometry in return AnyView( VStack(alignment: .leading) { ForEach(0..<self.rowCount) { rowIndex in HStack { ForEach(0..<self.rowLength) { elementIndex in if ((rowIndex * self.rowLength) + elementIndex < self.totalElements) { Button(action: { print(msg: "\((rowIndex * self.rowLength) + elementIndex)") }) { Text("\( (rowIndex * self.rowLength) + elementIndex)") } .background(Color.purple) .foregroundColor(Color.white) } } // ForEach elementIndex } // HStack } // ForEach rowIndex } // VStack ) // AnyView } // GeometryReader } }