u/coff3ein r/swift • Recommends
On “Is a "View" just a div?”
Yes, you can consider a SwiftUI View to be like a div from the web world. Many of the builtin SwiftUI views like List and Section carry some semantic meaning, that influences how they look on the different Apple platforms.
But that is not the complete picture. In SwiftUI, you compose the screens of your app by nesting many views inside each other. But also, every view modifier wraps your view inside a new 'anonymous' view, to which the next modifier is applied, and so on. "Aren't hundreds of nested views very inefficient?" you might ask. Because in UIKit, we want to keep our view tree as shallow as we can for performance.
But SwiftUI heavily flattens and optimises the view tree before it r…