1. What is Layout protocol?
AdvancedAnswer: iOS 16+ protocol for custom layout
Layout protocol creates custom layouts. sizeThatFits, placeSubviews methods. Replace GeometryReader. Efficient. Flexible positioning. Advanced layouts. iOS 16+.
24 questions that come up in SwiftUI technical interviews, each with the answer and an explanation of why it is right.
Test yourself — 90 question bankAnswer: iOS 16+ protocol for custom layout
Layout protocol creates custom layouts. sizeThatFits, placeSubviews methods. Replace GeometryReader. Efficient. Flexible positioning. Advanced layouts. iOS 16+.
Answer: Declarative UI framework for Apple platforms
SwiftUI is Apple's declarative UI framework. Build interfaces with Swift code. Cross-platform (iOS, macOS, watchOS, tvOS). Reactive updates. Modern paradigm. iOS 13+.
Answer: Scrollable collection of rows
List displays rows: List { ForEach(items) { item in Text(item.name) } }. Automatic scrolling. Built-in styles. Swipe actions. Essential collection view.
Answer: Iterates over collection creating views
ForEach creates views from data: ForEach(items) { item in Text(item.name) }. Requires Identifiable or id parameter. Dynamic views. Performance optimized.
Answer: Protocol defining piece of UI
View protocol defines UI: struct MyView: View { var body: some View }. Basic building block. Declarative. Lightweight. Compose complex UIs from simple views.
Answer: Result builder for view DSL
@ViewBuilder enables SwiftUI DSL. Implicit returns, if/else, switch. Custom ViewBuilder functions. Declarative syntax. Result builder. Enables view composition.
Answer: @ViewBuilder function returning views
Custom ViewBuilder: @ViewBuilder func makeView() -> some View. Enables DSL in custom APIs. Trailing closure. Clean API design. Component libraries.
Answer: Container for navigation hierarchy
NavigationView enables navigation: NavigationView { ContentView() }. Navigation bar. Push/pop views. Title, buttons. Stack-based navigation. iOS pattern.
Answer: Required computed property returning view content
body is computed property: var body: some View { Text("Hello") }. Returns view hierarchy. SwiftUI calls when rendering. Opaque return type. Core View requirement.
Answer: Navigates to destination view
NavigationLink navigates: NavigationLink("Next", destination: DetailView()). Programmatic: NavigationLink(isActive: $isShowing). Push navigation. Common pattern.
Answer: Displays read-only text
Text displays strings: Text("Hello, World!"). Styling modifiers. String interpolation: Text("Count: \\(count)"). Multi-line support. Basic view primitive.
Answer: Type-erased wrapper for any view
AnyView erases type: AnyView(Text("Hi")). Heterogeneous collections. Loss of type info. Performance cost. Use sparingly. Group preferred. Type flexibility.
Answer: @ViewBuilder preserves types, AnyView erases
@ViewBuilder maintains types (opaque). AnyView erases types. ViewBuilder more efficient. Prefer ViewBuilder. AnyView for stored properties. Performance consideration.
Answer: Displays images from assets or system
Image displays images: Image("photo") or Image(systemName: "star.fill"). SF Symbols integration. Resizable, aspect fit/fill. Tint colors. Essential view.
Answer: Tab-based navigation container
TabView creates tabs: TabView { View1().tabItem { Label("Tab1", systemImage: "star") } }. Bottom tab bar. Page style available. Multi-view navigation.
Answer: Modal presentation
Sheet presents modally: .sheet(isPresented: $showing) { DetailView() }. Dismiss gesture. Full screen or card. iOS modal pattern. Common presentation.
Answer: Optimizes view updates with Equatable
EquatableView optimizes: .equatable(). Requires Equatable conformance. Prevents unnecessary updates. Performance optimization. Use for expensive views. Manual optimization.
Answer: Interactive element triggering action
Button triggers actions: Button("Tap Me") { action() }. Label can be any view. Styling with ButtonStyle. Common interaction element. Simple syntax.
Answer: System alert dialog
Alert shows dialog: .alert("Title", isPresented: $showing) { Button("OK") { } }. System styled. Actions. Destructive options. User confirmation.
Answer: Property wrapper for view-local mutable state
@State private var count = 0. View-owned state. Changes trigger re-render. Value type storage. Source of truth. SwiftUI manages storage. View lifecycle.
Answer: Renders view hierarchy into single layer
drawingGroup() composites: .drawingGroup(). Metal rendering. Performance for complex graphics. Many shapes/paths. Trade-off: memory vs speed. Profiling needed.
Answer: Uses value itself as identifier
ForEach(items, id: \\.self) uses value as ID. Works for Hashable types. Simple arrays. No Identifiable needed. Uniqueness required. Common pattern.
Answer: State is view-internal, not passed from parent
@State should be private. View owns state. Not initialized from outside. Parent passes via @Binding. Clear ownership. Prevents external modification. Design pattern.
Answer: Observes external ObservableObject
@ObservedObject var model: MyModel. External reference type. Changes trigger updates. Class with ObservableObject. Published properties. MVVM pattern.
The full SwiftUI bank has 90 questions across 3 difficulty levels — timed, shuffled, and scored.
Take the SwiftUI quiz