DevPrep

All topics › SwiftUI

some View, ViewBuilder and result builders — what are they?

Middle PRO

some View

some View is an opaque return type: the function returns one concrete type conforming to View, but the type's name is hidden from the caller. The real type of body looks like ModifiedContent<VStack<TupleView<(Text, Button<Text>)>>, _PaddingLayout> — impossible to write by hand. The compiler knows the type statically, so SwiftUI can compare the old and new trees structurally and keep state in the right nodes. AnyView is the opposite: it erases the type, deprives the framework of diffing information and forces the subtree to be recreated when the content changes.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store