Skip to content
tezvyn:

Compare UIKit Auto Layout and SwiftUI layout systems

Source: developer.apple.comMediumHow cards are made

Compare UIKit Auto Layout and SwiftUI layout systems

Tests imperative versus declarative layout paradigms. Contrast UIKit's constraint solver with SwiftUI's two-pass sizing and composition via stacks and modifiers instead of anchors. Red flag: claiming SwiftUI uses Auto Layout under the hood.

What's really being asked

This question tests whether you understand the fundamental architectural difference between UIKit's imperative, constraint-driven layout system and SwiftUI's declarative, composition-driven approach. Interviewers want to see that you know UIKit relies on an external constraint solver while SwiftUI uses an internal two-pass sizing negotiation. They are looking for awareness of how this shift changes performance characteristics, debugging strategies, and mental models for alignment and spacing.

The full answer

First, explain that UIKit Auto Layout builds a constraint graph of linear equations that the solver resolves to produce frames, using NSLayoutConstraint, anchors, and priority values. Second, describe SwiftUI's layout as a recursive two-pass system where a parent proposes a size to its child, the child chooses its own size based on that offer, and the parent places the child in its coordinate space. Third, note that SwiftUI expresses layout through structural composition, specifically HStack, VStack, ZStack, Spacer, and frame modifiers, rather than through a separate constraint system. Fourth, mention that SwiftUI invalidates and recomputes layout when state changes, whereas UIKit requires manual invalidation or constraint updates, and that SwiftUI's approach eliminates ambiguous layout warnings but introduces its own complexity with fixedSize and layout priorities.

The mistakes people make

A major red flag is claiming SwiftUI simply wraps Auto Layout or translates into constraints under the hood. Another is describing SwiftUI layout as magic without explaining the parent-child size negotiation. Avoid saying Auto Layout is more powerful; instead, acknowledge that both handle complex layouts but SwiftUI pushes you toward predictable, composable structures. Do not confuse SwiftUI stacks with UIKit UIStackView without noting that UIStackView itself uses Auto Layout internally while SwiftUI stacks are primitive layout containers.

What usually comes next

The interviewer may ask how you would replicate a complex constraint, such as equal widths or aspect ratios, in SwiftUI. They might probe performance by asking about the cost of deep view hierarchies in SwiftUI versus UIKit, or ask how UIHostingController bridges the two worlds. Another common follow-up is asking how you debug layout issues in SwiftUI without Interface Builder or view debugger constraints.

A concrete example

Consider a login screen with a logo, two text fields, and a button centered vertically with padding. In UIKit, you would pin the logo top anchor to the safe area, center the text fields horizontally with equal widths, and set the button bottom anchor with a greater-than-or-equal constraint to the keyboard. In SwiftUI, you wrap the elements in a VStack, apply Spacer above and below to center the group, use frame maxWidth infinity on the text fields to mimic equal widths, and apply padding as a modifier on the stack. This shows how UIKit thinks in external relationships between independent views while SwiftUI thinks in nested containers that own their children's arrangement.

Interview question

Which statement accurately describes a key architectural difference between UIKit Auto Layout and SwiftUI?

  • a.UIKit uses a declarative two-pass sizing system where parents propose sizes to children.
  • b.UIKit uses an external constraint solver while SwiftUI uses parent-child two-pass size negotiation.Correct
  • c.SwiftUI translates its layout modifiers into Auto Layout constraints under the hood.
  • d.SwiftUI relies on an external constraint solver that resolves linear equations to produce view frames.
Why?

UIKit Auto Layout depends on an external solver to resolve linear equation constraints into frames, while SwiftUI layout is driven by an internal two-pass size negotiation between parent and child. Option C represents a common misconception; SwiftUI does not wrap or compile down to Auto Layout constraints but instead uses its own compositional layout engine.

Just read this? Test yourself on what you have been reading.

Read the original → developer.apple.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on ios — each one lists the topics its interview covers.

See open roles