Swiftui
36 bites tagged Swiftui — interview questions with model answers, and 60-second explainers.
Building a Card Flip Animation in SwiftUI
Drive a flipped state, rotate both faces with rotation3DEffect, hide the back face. SwiftUI animation and 3D transform fluency. forgetting the back is mirrored or showing both faces at once.
View identity in SwiftUI and the .id() modifier
Identity links a view to its persistent state and transitions; structural identity comes from position, explicit identity from .id(); changing the id resets state and forces a new view. how SwiftUI tracks views across updates.
Animate a SwiftUI Shape morphing point count
Expose a continuous sides value as animatableData so SwiftUI interpolates it, then compute the path from that fractional value each frame. Driving custom interpolation with animatableData.
Implicit .animation() vs explicit withAnimation
.animation(value:) animates a view when a tracked value changes; withAnimation wraps the state mutation so all dependent views animate. How SwiftUI ties animation to state changes.
How do you build a custom SwiftUI Layout?
Conform to Layout, implement sizeThatFits to report the container size for a proposal, and placeSubviews to position each subview using its measured size. SwiftUI's Layout protocol for bespoke arrangements.
Design state-driven navigation for a conditional wizard in UIKit and SwiftUI
This tests separating navigation state from UI. Model the flow as a state machine enum, derive the stack from state, and unit test transitions in plain Swift. A red flag is imperative pushes inside views or view controllers.
What NavigationView limitations did NavigationStack solve for programmatic navigation?
This tests why NavigationView programmatic navigation was brittle. A strong answer contrasts scattered NavigationLink isActive booleans and broken multi-destination stacks against NavigationStack's unified path array. A red flag is calling it a simple rename.
How do you pop to root in SwiftUI NavigationStack?
This tests declarative state-driven navigation. A strong answer binds NavigationStack to a NavigationPath, passes the binding down, and clears the path to pop to root. A red flag is suggesting UIKit popToRootViewController or legacy isActive hacks.
Implement SwiftUI navigation between list and detail with product ID
Tests modern SwiftUI navigation and clean data flow. Great answer: NavigationStack with NavigationLink(value:) and navigationDestination(for:), plus a bound path for programmatic control.
Integrate SwiftUI into UIKit and wrap UIKit for SwiftUI
Tests bridging architecture between UIKit and SwiftUI using UIHostingController and UIViewRepresentable. A strong answer names hosting controllers for SwiftUI in UIKit, representable protocols for UIKit in SwiftUI, and lifecycle hooks.
Differences between @State, @Binding, @ObservedObject, and @EnvironmentObject
Tests SwiftUI state ownership and propagation. @State owns local value types; @Binding borrows for two-way edits; @ObservedObject accepts an external ObservableObject; @EnvironmentObject reads one from the environment.
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 is @State in SwiftUI and how does it affect the view?
Tests declarative data flow ownership. A strong answer defines @State as private value-type storage owned by the view that triggers a body re-evaluation on mutation. Red flag: confusing it with external data sources like @ObservedObject or @Binding.
MatchedGeometryEffect: Shared Element Hero Transitions
MatchedGeometryEffect lets two views share one spatial identity, so a thumbnail can appear to fly into a detail sheet across view hierarchies. It only works if both views exist simultaneously during a withAnimation block; otherwise the transition snaps.
withAnimation: The Implicit Animation Transaction
withAnimation wraps state changes in a transaction, telling SwiftUI to tween affected layout automatically. Call it from button actions or view model methods to animate many views from one state flip.
Map Data to Views Using navigationDestination
navigationDestination turns NavigationStack into a router: register a view per data type, then push raw values. It frees view models from creating views. Using it outside NavigationStack or mixing it with old NavigationLink destinations silently breaks…
SwiftUI Sheets: State-Driven Modal Overlays
A SwiftUI sheet is a temporary, state-bound overlay that slides over your current view. Use it for focused tasks like composing a message or picking a date. State and environment values do not automatically propagate into its isolated view hierarchy.
TCA: Unidirectional State for SwiftUI
TCA is a strict pipeline for SwiftUI: state and actions enter a pure reducer, emitting new state and effects. Use it when complex flows need reproducible tests without launching the app.
Result Builders: Declarative Swift DSLs
Result builders teach the compiler to fold expressions into one combined value, enabling declarative DSLs. SwiftUI relies on them to compose stacked views. Type errors surface on compiler-generated boilerplate instead of your original code.
GeometryEffect
GeometryEffect is a SwiftUI protocol for building custom animatable 2D transforms beyond the built-in offset, scaleEffect, and rotationEffect modifiers, by returning a ProjectionTransform that SwiftUI recomputes and animates on every frame.
Canvas in SwiftUI
Canvas is SwiftUI's view for fast, immediate mode drawing. Instead of composing many shape views, you draw paths, text, and images directly into a GraphicsContext, which is far cheaper for complex or animated graphics.
NavigationPath (SwiftUI)
NavigationPath is a type erased stack of navigation destinations that backs a SwiftUI NavigationStack, letting one path hold a mix of different hashable data types so you can push, pop and control deep, heterogeneous navigation flows programmatically.
NavigationSplitView: Adaptive Layouts for All Screen Sizes
NavigationSplitView is a responsive container for multi-column layouts. It shows a sidebar, content, and detail view on large screens but collapses to a stack on small ones. Use it for master-detail UIs like a mail app.
NavigationLink: Pushing Views in SwiftUI
NavigationLink is SwiftUI's declarative way to push a new view onto a navigation stack. You use it inside a `NavigationStack` to create drill-down UIs, like tapping a list item to see its details. The footgun is forgetting the parent `NavigationStack`.
Get Swiftui bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.