Guidelines for ViewThatFits to avoid run-time crashes

TLDR: What rules ensure you won't have sporadic run-time crashes when using ViewThatFits?

My app crashes - luckily reproducible. But the code appeared syntacticly and logically correct.

Simplified excerpt: https://github.com/alanrick/Experiment3

The crash is caused by ViewThatFits being overwhelmed by concurrent changes in other views, exacerbated by animation effects. In the original code the problem was even worse because I'd gone overboard and used ViewThatFits in sub-views making the whole thing too dynamic. 



My first rule is:

  1. Do not use nested ViewThatFits. 



But this alone is not sufficient. What other rules can I apply to ensure I won't have hard-to-detect run-time crashes when using ViewThatFits?

I'm wondering the same thing myself. I have two ForEach inside of a ViewThatFits and the code is working great when I build it locally. However, when I made a TestFlight build it was an instant crash at launch on the very same device.

The crash report says that it is SizeFittingState.applyChildren(selectLast:to:) that had the problem.

Apple replied today to say the problem has now been now fixed:

Xcode 16.3 beta (16E5104o)

https://developer.apple.com/download/ Posted Date: February 21, 2025

Guidelines for ViewThatFits to avoid run-time crashes
 
 
Q