SwiftUI interview questions
State ownership, Observation, view identity, navigation, layout and the SwiftUI bugs interviewers love to show you.
– interview-ready · 22 questions in this topic
– of 22 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- SwiftUI vs UIKit: key differencesPredict
- Which property wrapper for which data?Pick the fix
- @State vs a plain varPredict
- @StateObject vs @ObservedObjectPredict
- @Observable model keeps resettingSpot the bug · Pick the fix
- @Observable vs ObservableObjectPredict
- @Bindable for passed-in modelsPick the fix
- @Binding and the $ prefixPick the fix
- View identity: if/else vs a modifierPredict
- Why body runs often, and keeping it cheapPredict
- .task vs .onAppear + TaskSpot the bug
- .task(id:) and built-in debouncingPredict
- NavigationStack and deep linksPick the fix
- Custom environment values with @EntryPick the fix
- ViewModifier vs AnyViewPick the fix
- .animation(_:value:) vs withAnimationPredict
- GeometryReader vs ViewThatFits and LayoutPick the fix
- UIViewRepresentable feedback loopsSpot the bug
- Loading and error state in SwiftUISpot the bug
- @FocusStateFill the blank
- @ViewBuilderPick the fix
- A timer that re-renders the whole screenPick the fix
Practise this topic
Flashcards · 29
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 22 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 4 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Fix this PR · 4 reviews
Review a diff like a senior: flag the lines you'd comment on. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
.sheet vs .fullScreenCover
A sheet is a card the user can swipe down on iPhone; fullScreenCover covers the screen and must be dismissed in code.
AnyLayout
Wraps a Layout (for example HStackLayout or VStackLayout) so you can switch layouts without losing child state.
Swift 5.7+ · iOS 16.0+
@Previewable
Lets you declare @State directly inside a #Preview block (Xcode 16).
Swift 6.0+ · iOS 17.0+
Self._printChanges()
Debug-only helper that prints which dependency made a view's body run.
.id(_:)
Gives a view an explicit identity; changing the value resets its state and triggers transitions.
PreferenceKey
Sends values from children up to ancestors, read with onPreferenceChange.
@ScaledMetric
Scales a number (padding, icon size) with the user's Dynamic Type setting.
Printable cheat sheet · Review your weak spots in this topic