Skip to content
0:00 / 0:00

#swiftui#viewrendering#layoutengine

Chris Eidhof - A Day in the Life of a SwiftUI View

Swift TO

691 subscribers • 1 video on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Chris Eidhof

Intermediate. Assumes working knowledge.

3.8K views1 year ago2 recommendations

Mobile developmentSwiftiOS and SwiftUIRendering

Chris Eidhof explains how SwiftUI views are rendered, laid out, and updated under the hood.

Chris takes us through how a SwiftUI view is rendered, laid out and updated

Why it's here

2 people recommend this

What people say. Recommended to help understand how SwiftUI views differ from traditional DOM elements like divs.

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…

u/AlexanderMomchilovin r/swift • Recommends

On “Is a "View" just a div?”

This is an surprisingly apt analogy. In the web world, a `div` ***isn't*** what actually gets on screen. It's a minimal description of some UI element. It's the browser's job to interpret that description, and create/render one of its internal UI elements. You never get direct access to these, they're just implementation details of the web renderer. Similarly, Swift `View`s are just descriptions of views. It's the SwiftUI library's job to ask you for descriptions of the views you want, and for it to interpret that description to produce a view hierarchy of `NSView`, `UIView`, etc (depending on the platform). The actual elements being rendered are , but that's not something SwiftUI gives yo…