QUESTION OF THE WEEK
“
When do you know a view is too complex and should be split to keep logic separate?
— Danijela
You start a new SwiftUI View and it all looks good. A few more features, view elements, and buttons are added along the way. Two weeks later, your component is suddenly covering 400+ lines of code.
It's a debate many teams have when defining their SwiftFormat or SwiftLint configuration files. Should we throw a warning when a file becomes too long?
It's subjective to say a view is too complex or a file is too long. What I can say is that any component benefits from seperation of concern. If I ask you: "What is the single thing this view does?" and you find it difficult to answer with just one thing, you know there's a potential to split things up.
I sometimes feel bad to have a really small view component, but I always remind myself that this view might be a small seed that will slowly grow. Preparing your code for the future means looking ahead and make decisions early in the process.