What is Auto Layout and how does it work?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Swift & iOS basics — a prerequisite for any developer role.
Answer
Auto Layout is UIKit's constraint-based layout system that allows views to automatically calculate their size and position based on relationships (constraints) between views. It adapts to different screen sizes, orientations, and dynamic content. Constraints define: a view's width, height, position relative to other views or the superview. Each constraint is a linear equation: view1.attribute = multiplier × view2.attribute + constant. Anchors API (programmatic): // Add subview: view.addSubview(label) label.translatesAutoresizingMaskIntoConstraints = false // REQUIRED NSLayoutConstraint.activate([ label.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 16), label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16), label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16) ]). UIStackView: container that arranges subviews automatically: let stack = UIStackView(arrangedSubviews: [label, button]) stack.axis = .vertical stack.spacing = 8 stack.distribution = .fill. Visual Format Language: string-based constraints (less common now): NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[view]-16-|", ...). Compression resistance and content hugging: priorities that control how views behave when there's extra or insufficient space. Safe area layout guide: accounts for notch, home indicator, status bar. Use safeAreaLayoutGuide instead of direct superview anchors. Intrinsic content size: some views (UILabel, UIButton) have a natural size based on content — Auto Layout respects this without explicit width/height constraints.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Swift & iOS project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is UITableView and how do you implement it?
Next
What is a closure in Swift and how do you avoid retain cycles?