Hey!
Our team is experiencing some issue in a large SwiftUI application. When loading large views, the app crashes with a EXC_BAD_ACCESS signal. This signal can be reported by Xcode either on the @main attribute, inside a view hierarchy, or any order property that is accessed in the view hierarchy. After some investigation we found several possible workarounds:
- Splitting up the view into smaller subviews
- Wrapping parts of the view into an AnyView, which isn't ideal.
However, this only temporarily solved the issue. As the app becomes bigger, we run into this problem more frequently. When trying to reproduce this issue in a clean Xcode project, I came up with the following:
struct ContentView: View {
var body: some View {
Text("Hello")
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
.task {}
}
}
When running this, the app immediately crashes on an iPhone 14 (YMMV on different (newer) devices). Of course such a view is not very likely to occur, but in total a view hierarchy could have this many view modifiers. Is there some limit we should we aware of? How can we circumvent this?
Thanks!