SwiftUI interview questions
49 questions from real iOS interviews. Topics: State, Binding, Observable, view identity, layout, performance, UIKit interop.
- SwiftUIShort answer
SwiftUI vs UIKit rendering
How is the way SwiftUI draws the screen fundamentally different from UIKit?
#swiftui #uikit #declarative #rendering
- SwiftUIMultiple choice
@State and @Binding
You're building a SwiftUI settings screen. A child view SettingsRow with a toggle needs to read and change an isOn value the parent owns. Which property declar…
#state #binding #data-flow #source-of-truth
- SwiftUIShort answer
Diagnosing @State updates
A junior asks you why the screen doesn't update after they change a @State value in SwiftUI. Start by explaining what @State is.
#state #update #debugging #observable
- SwiftUIShort answer
App entry point
In a SwiftUI app, what does @main mean?
#main #app-protocol #scene #windowgroup
- SwiftUIMultiple choice
Presenting a sheet
In a SwiftUI list, tapping an item should present that item's detail in a sheet. With many items, what's the most appropriate approach?
#sheet #modal #presentation #item
- SwiftUIShort answer
NavigationStack navigation
How do you implement navigation between screens in SwiftUI?
#navigationstack #navigationpath #navigationlink #deep-link
- SwiftUIMultiple choicePayPal
Modifier order
This is an interview where we look at SwiftUI code together and fix it. Which statement about the rendered result of these two lines is correct? …
#modifier #background #padding #modifier-order
- SwiftUIMultiple choiceFidelity Investments
Choosing property wrappers
Select all the correctly matched pairs of situation and SwiftUI property wrapper. (Assume iOS 16 and ObservableObject.)
#state #stateobject #observedobject #environmentobject
- SwiftUIShort answer
View as a struct
UIView is a class, so why was SwiftUI's View designed as a struct?
#view #struct #value-type #protocol
- SwiftUIMultiple choice
@StateObject vs @ObservedObject
In this SwiftUI view, ItemListView's data resets every time the parent view is re-evaluated. What's the cause, and what's the right fix? …
#stateobject #observedobject #observableobject #lifetime
- SwiftUIMultiple choice
Observation migration
You're moving a SwiftUI app's ObservableObject code to @Observable. Select all the correct migrations.
#observable #migration #bindable #environment
- SwiftUIShort answer
Data flow design
Using the single source of truth principle in SwiftUI, how do you decide which view should own a given piece of state?
#data-flow #source-of-truth #binding #environment
- SwiftUIMultiple choice
Environment injection
In a SwiftUI app you injected .environment(session) at an intermediate view (HomeView) as shown below. ProfileView, which uses @Environment(Session.self) var s…
#environment #environmentobject #injection #crash
- SwiftUIShort answer
SwiftUI view lifecycle
SwiftUI views have no viewDidLoad or viewWillAppear like UIKit. How does a view actually get created, appear, update, and disappear? Center your answer on how …
#lifecycle #onappear #task #body
- SwiftUIShort answer
Embedding SwiftUI in UIKit
How do you put a SwiftUI screen into a UIKit app?
#uiviewrepresentable #uihostingcontroller #interop #coordinator
- SwiftUIMultiple choice
UIViewRepresentable behavior
Select all the correct statements about SwiftUI's UIViewRepresentable.
#uiviewrepresentable #coordinator #updateuiview #interop
- SwiftUIMultiple choice
Stack and Spacer layout
Select all the correct statements about the layout result of this SwiftUI view. …
#hstack #spacer #frame #maxwidth
- SwiftUIShort answer
Reusable component design
You're building a design system's card component in SwiftUI to reuse across many screens. When would you use each approach (a custom View, a ViewModifier, a St…
#viewmodifier #reusable #viewbuilder #style
- SwiftUIMultiple choice
@Published and view updates
Select all the correct statements about how ObservableObject's @Published updates SwiftUI views.
#published #observableobject #objectwillchange #combine
- SwiftUIMultiple choiceCapital One
onChange vs onReceive
Select all the correct statements about SwiftUI's onChange(of:) and onReceive(_:).
#onchange #onreceive #combine #modifier
- SwiftUIShort answer삼성전자
List scrolling diagnosis
You got a report that a SwiftUI List stutters while scrolling, and that row toggles and images change to the wrong ones or flicker. In what order do you suspec…
#list #lazyvstack #identifiable #performance
- SwiftUIMultiple choice삼성전자
Form validation state design
This is SwiftUI live coding. A sign-up screen has four fields (name, ID, password, password confirmation) and a submit button. If name or ID is empty, show a w…
#form #validation #alert #state
- SwiftUIShort answerSwiggy
UIKit to SwiftUI migration
You want to move a service app built in UIKit over to SwiftUI. What strategy do you use to introduce it?
#migration #uihostingcontroller #navigation #interop
- SwiftUIShort answerZomato
State-driven view switch
This is a 15-minute SwiftUI live coding exercise. Tapping an "Add" button should show a quantity stepper (minus/plus) in the same spot, and when the quantity h…
#state #conditional-view #stepper #animation
- SwiftUIShort answerRobinhood
Swift Charts implementation
This is on-site coding. For a stock app, how would you build a Chart in Swift Charts that draws the last 30 days of closing prices as a line, with axes, range,…
#swift-charts #chart #linemark #visualization
- SwiftUIShort answerAlibaba Group
WidgetKit and SwiftUI
You've been assigned home screen widget development. Why can widgets only be built with SwiftUI and not UIKit?
#widgetkit #widget #timeline #appintent
- SwiftUIShort answerMercari
SwiftUI state ownership
In a SwiftUI product editing screen, the parent view owns the product model and a child view edits just the price field. Among @State, @Binding, and @Observabl…
#swiftui #state #binding #observation
- SwiftUIShort answerHSBCinterview report
Choosing SwiftUI or UIKit
You're adding a new account detail screen to a banking app built in UIKit. By what criteria would you decide whether to build this screen in SwiftUI or UIKit?
#swiftui #uikit #integration #hosting-controller
- SwiftUIShort answerPelotoninterview report
Single state tally screen
A counter screen built in SwiftUI has increment, decrement, and reset buttons plus a display of the current value. How would you arrange the state so the displ…
#swiftui #state #counter #single-source
- SwiftUIShort answerExpediainterview report
SwiftUI API loading state
A SwiftUI list screen loads data from a hotel API. To handle loading, success, no results, and error on screen without missing one, how would you model the sta…
#swiftui #task #loading-state #api
- SwiftUIShort answer요기요interview report
SwiftUI async MainActor state
A SwiftUI order list ViewModel calls an async API and then changes the screen state with the result. Under Swift 6 strict concurrency, which part of this ViewM…
#swiftui #mainactor #async-await #error-state
- SwiftUIShort answer빗썸interview report
List item identity
In a SwiftUI List showing live prices, every price update makes rows flicker and reappear and the scroll position jumps. How should you define the model's Iden…
#swiftui #list #identity #realtime
- SwiftUIShort answer중고나라interview report
Unidirectional state flow
A used-goods listing screen built in SwiftUI has input fields, validation, submission, and error display all tangled together. If you reorganized it as a unidi…
#swiftui #unidirectional #state #validation
- SwiftUIShort answer
Observation framework
In SwiftUI, what does the iOS 17 @Observable macro give you over the older ObservableObject plus @Published approach? Ground it in how the two work internally.
#observable #observation #observableobject #published
- SwiftUIShort answer
View identity
In the code below, toggling isCompact wipes whatever was typed in the text field. Can you explain why using SwiftUI's concept of identity? …
#identity #structural-identity #explicit-identity #id
- SwiftUIMultiple choice
ForEach identifiers
In this SwiftUI to-do list, inserting an item at the front makes every row flicker instead of animating the insertion, and each row's toggle state shifts down …
#foreach #identifiable #id #list
- SwiftUIShort answer
SwiftUI layout algorithm
Can you walk me through the three steps that determine a SwiftUI layout?
#layout #proposal #size #frame
- SwiftUIShort answer
MVVM in SwiftUI
If you apply MVVM to a SwiftUI screen, how do you define the ViewModel and how does the view own it?
#mvvm #viewmodel #observable #mainactor
- SwiftUIMultiple choice
.task vs onAppear
In a SwiftUI view that loads data, what's the correct statement about how these two pieces of code behave differently? …
#task #onappear #cancellation #async
- SwiftUIShort answer
SwiftData and SwiftUI
For a new SwiftUI app's local storage you picked SwiftData over Core Data. How does SwiftData integrate with SwiftUI?
#swiftdata #coredata #query #modelcontainer
- SwiftUIShort answerCapital One
switchToLatest search pipeline
You're building a Combine pipeline for a SwiftUI search screen that calls the API as the user types. What's the difference between putting switchToLatest() aft…
#combine #switchtolatest #flatmap #debounce
- SwiftUIShort answerCapital One
Combine list-detail live coding
This is a 20-minute live coding exercise. Using only Combine, build a two-screen SwiftUI app that fetches a list from an API, shows it, and navigates to a deta…
#combine #live-coding #navigationstack #observableobject
- SwiftUIShort answer크림
@Observable ownership and passing
When working with an iOS 17 @Observable class in SwiftUI views, using "who owns it" and "how is it passed" as the criteria, when do you use @State, a plain pro…
#observation #observable #state #bindable
- SwiftUIShort answer휴레이포지티브
Search tab design
This is a take-home assignment. Build the App Store "Search" tab in SwiftUI using the iTunes Search API. You need recent search terms (stored locally), a resul…
#searchable #task-id #debounce #recent-searches
- SwiftUIShort answer네이버웹툰
Observation dependency tracking
In iOS 17 SwiftUI, when one property on an @Observable model changes, only some of the views using that model redraw, not all of them. What does SwiftUI use to…
#observation #observable #swiftui #ios17
- SwiftUIShort answer
SwiftUI performance diagnosis
On a dashboard screen built in SwiftUI, the whole screen stutters on every character typed into a text field. What's your hypothesis for what's going on?
#performance #body #printchanges #instruments
- SwiftUIShort answerPayPalinterview report
Finding SwiftUI defects
This is a SwiftUI live coding review. Find as many defects as you can in the feed screen code below, and for each one say why it's a problem and how you'd fix …
#debugging #code-review #observedobject #foreach
- SwiftUIMultiple choice
Observation tracking granularity
In this SwiftUI plus Observation code, when only store.count is incremented, select all the views whose body is re-evaluated. …
#observable #observation #tracking #body
- SwiftUIShort answer
Large list performance
A SwiftUI feed showing thousands of items stutters while scrolling. Based on the internal differences between List and ScrollView + LazyVStack, which do you ch…
#list #lazyvstack #performance #anyview