precondition failure: invalid input index when using GeometryReader in SwiftUI starting with iOS 13.4

Viewed 1194

Yesterday I upgraded XCode and my project to iOS 13.4 and I started to see a lot of failures in around views that use GeometryReaders.

The error does not reveal anything besides "precondition failure: invalid input index"

2 Answers

I had the exact same issue after upgrading to 13.4.1.

I installed a simulator with 13.3.3 and it didn't have the issue.

What ended up causing the issue was having a GeometryReader as an inner view of a NavigationView. Making the GeometryReader the top-most view fixed it for me.

After debugging and starting to lose my mind, I found that each view that had a GeometryReader also was using onReceive with a call to a function that had Combine code.

Basically I was calling .collect() on the Publisher and sink-ing the result to a variable.

After I removed the Combine code and started to use old fashioned array operations, all started working again.

Related