Is there a documentation on how SwiftUI works at lower level?

Hello guys,

I'm curious, are there any docs that refer to how SwiftUI works at lower level? I didn't follow the forums for a long time and I'm guessing there might be some info here as well (?). Reading the official docs doesn't help.
I'm not looking for an in-depth view, I just need to understand it top level so I can debug or better understand things (like @ViewBuilders)

SwiftUI isn't open source, so only apple employees know how it works at lower level, but I can link you to some of the newest features of Swift that SwiftUI uses a lot:
omitting return
property wrappers (for example @State)
Identifiable (we saw that it's in SwiftUI, and decided that it would be better if there was a type like that in standard library)
opaque types (it allows you to write some View)
function builders (Not officially part of Swift yet)
There's also a lot of Combine in SwiftUI, but that's another closed source apple framework

Hey, thanks for the reply. Some of these did indeed caused some confusion (property wrappers and function buiulders). Also, what I'm having trouble understanding, when you write:

HStack(alignment: .lastTextBaseline, spacing: 0) {


It almost looks like you have an init with the last parameter a closure (but there is not _ in, which, last time I was working with Swift was required). Also everything that goes between {} doesn't act as if we'd be in a closure. Are these the function builders? I guessing this should be a compiler feature...

Still, thanks a lot for the info, really helpful!

_ in isn't required if your closure uses all parameters using $0 syntax (in reality you just need to use the last one). In your case that closure takes zero parameters, and uses all of them, so _ in isn't required


It is. Unofficially right now, but it will be official when it goes through swift evolution process

Of, course. My bad.

I feel like I'm on the right path now, most of the confusion was around function builders and property wrappers.

Thanks again

1 Like

SwiftUI also make use of Dynamic Member Lookup to access member field binding.

Use Cmd-Click/"Go to definition" on any SwiftUI type to see its "source". What it shows is not the real source, but it does let you peek inside a little.

If you Cmd-Click on @ViewBuilder, "Go to definition", you can see it generates TupleView: a tuple of up to 9 View's, this is why you can only have up to 9 views inside any container like VStack. It also can do ForEach, IfElse. You need to know how to use these types if you want to write you own container.

1 Like