Native iOS Engineering, SwiftUI & Platform Architecture Master Interview Bank
Native iOS Architecture, SwiftUI State & Lifecycle, Combine, SwiftData / Core Data, Keychain & Secure Enclave, Instruments Profiling, and MVVM/TCA.
Curriculum Roadmap & Learning Path
3 StagesPart 1: SwiftUI Architecture, State & App Lifecycle (1 - 10)
10 QuestionsWhat is the difference between SwiftUI and UIKit?
UIKit (Imperative - Legacy/Mature): Event-driven UI framework since iOS 2.0 • SwiftUI (Declarative - Modern Standard): Introduced in iOS 13+.
What is the SwiftUI View Protocol and why are views structs?
In SwiftUI, every view conforms to the View protocol, requiring a body computed property: Views are lightweight structs, not reference classes! • Creating, destroying, and recreating struct instances on the stack takes nanoseconds and consumes minimal memory.
What is the difference between `@State` and `@Binding` in SwiftUI?
@State: Declares local, private source of truth owned by the view • @Binding: Two-way reference to state owned by an ancestor/parent view without owning or duplicating the data.
What is the difference between `@StateObject` and `@ObservedObject`?
Both observe classes conforming to ObservableObject: @StateObject (Owner): The view instantiates and owns the object • @ObservedObject (Consumer): The view receives an already-created object from a parent view • Rule: Create with @StateObject; pass down with @ObservedObject.
What is the `@Observable` macro in iOS 17+ (Observation Framework)?
Replaces the legacy ObservableObject and @Published property wrappers: Just annotate your class with @Observable • SwiftUI automatically tracks property access down to the specific field level: if a view only reads user.name, changes to user.age will NOT • Eliminates @StateObject and @ObservedObject boilerplate entirely.
What is the Combine Framework and what are Publishers, Subscribers, and Operators?
Apple's reactive declarative framework for processing asynchronous events over time: Publisher: Emits a sequence of values over time (e.g. NotificationCenter.default.publisher, PassthroughSubject) • Operator: Transforms, filters, or combines values (.map.filter.debounce(for:scheduler:)).
What is SwiftData and how does it compare to Core Data?
Core Data (Legacy): Powerful object-relational mapping framework • SwiftData (Modern - iOS 17+): Swift-native replacement for Core Data • Models declared using the @Model macro directly on pure Swift classes • Queries declared using the #Predicate macro with full compile-time type checking.
What are Keychain Services and how do they differ from `UserDefaults`?
UserDefaults: Plain plist XML file stored on the device • Keychain: Hardware-encrypted, secure SQLite database managed by the OS • Data remains encrypted even if the device is backed up • Supports access control policies: kSecAttrAccessibleAfterFirstUnlock.
What is the Secure Enclave on Apple Devices?
A dedicated hardware-isolated security coprocessor separate from the main Apple Silicon CPU: Generates and stores private cryptographic keys (elliptic curve P-256) • The private key never leaves the Secure Enclave!
How do you implement Dependency Injection in iOS applications?
Avoid hardcoding concrete dependencies inside classes: Protocol-Based DI: Define an interface protocol (AuthServiceProtocol), inject it via the class initializer.
Part 2: Combine, Persistence, Security & Networking (11 - 24)
14 QuestionsWhat is Memory Profiling with Xcode Instruments (Allocations vs Leaks)?
Allocations Instrument: Tracks heap memory growth and object lifecycles over time • Leaks Instrument: Periodically scans process memory for unreferenced memory blocks and cycles that can never be freed • Generation Analysis: Marks a baseline before entering a screen and evaluates delta after exiting; any retained memory indicates a leak.
How does SwiftUI Layout and GeometryReader work internally?
SwiftUI layout operates in 3 distinct phases: Parent proposes a size to the child view • Child chooses its own size based on its content proposals • Parent places the child within its coordinate space • GeometryReader Trap: A GeometryReader eagerly expands to fill all available space proposed by its parent!.
What is the difference between VIPER, MVVM, and Composable Architecture (TCA)?
MVVM (Model-View-ViewModel): Industry standard • VIPER (View, Interactor, Presenter, Entity, Router): Strict single-responsibility enterprise pattern • TCA (The Composable Architecture): Unidirectional data flow inspired by Elm and Redux • Single state tree, Actions, and pure Reducer functions.
How does Background Execution work on iOS (BackgroundTasks framework)?
iOS suspends apps within seconds of entering the background: BGTaskScheduler: Used for scheduling deferrable background maintenance • BGAppRefreshTask: Short ~30-second window to fetch latest news/feeds.
What are Dynamic Frameworks vs Static Libraries on iOS?
Static Library (.a): Linked directly into the application executable binary at compile time • Dynamic Framework (.framework / .dylib): Linked dynamically at app launch by dyld (Dynamic Linker).
What is Method Swizzling and why is it dangerous in Swift?
Method Swizzling uses the Objective-C runtime to swap the implementation of two methods at runtime: Often used by analytics SDKs (Firebase, New Relic) to automatically track screen views by swizzling viewDidAppear.
How do you implement App Clip architecture?
An App Clip is a lightweight, instantaneous mini-slice of your app (< 15 MB) launched via NFC tags, QR codes, or Safari smart banners without downloading the full app from the App Store: Must launch in under 3 seconds • Built as a dedicated target sharing shared frameworks with the parent app.
How does URLSession connection caching and HTTP/3 support work on iOS?
URLSession natively supports HTTP/2 multiplexing and HTTP/3 (QUIC over UDP since iOS 15) • Manages connection pools and TLS session resumption automatically • Caching behavior is configured via URLRequest.CachePolicy (useProtocolCachePolicy, returnCacheDataElseLoad) backed by URLCache storing cached.
What is App Store Receipt Validation (Device Check vs App Attest)?
Prevents piracy and fraud: App Attest (DCAppAttestService): Uses the Secure Enclave to generate a hardware-backed cryptographic key pair, asserting to your backend server • Replaces legacy, easily forgeable client-side receipt parsing.
How does Core Data Faulting and Batch Operations work?
Faulting: Core Data instantiates NSManagedObject instances as lightweight placeholder "faults" without fetching their column data from disk • Batch Operations (NSBatchUpdateRequest, NSBatchDeleteRequest): Executes operations directly on the underlying SQLite database file without.
What is the `Layout` protocol in SwiftUI (iOS 16+)?
Allows creating custom container layouts (e.g. Masonry, FlowLayout, Radial layouts) without falling back to UIKit: Requires implementing two methods • sizeThatFits(proposal:subviews:cache:): Calculates the overall container size for a proposed size.
When should you choose Native iOS (Swift + SwiftUI) over Cross-Platform (React Native / Flutter)?
Choose Native iOS • Apps requiring deep integration with Apple hardware (ARKit, Metal, CoreML, CoreBluetooth, LiDAR) • Premium consumer apps where fluid 120Hz ProMotion animations, platform-native gestures, and zero frame jank are core to brand identity.
How does the iOS Application Lifecycle work (AppDelegate, SceneDelegate, and UIScenePhase)?
AppDelegate: Manages process-level events (app launch, APNs token registration) • SceneDelegate / UIScenePhase: Manages multi-window UI lifecycle states: active, inactive, and background.
What is NavigationStack in modern SwiftUI (iOS 16+) and how does it enable data-driven deep linking?
Replaced the deprecated NavigationView. Uses a strongly typed NavigationPath collection or state array, allowing programmatically pushing, popping to root, or restoring deep navigation stacks from serialized state.
Part 3: Instruments Profiling, App Architecture & Production Hardening (25 - 35)
26 QuestionsHow does ViewModifier and custom UI component styling work in SwiftUI?
ViewModifier encapsulates reusable view transformations, returning an altered view without copy-pasting styling modifier chains.
How do LazyVStack and LazyHStack optimize memory in SwiftUI lists?
Standard VStack creates and calculates body layouts for all subviews immediately upon instantiation. LazyVStack creates subviews only when they scroll into the visible viewport, preventing memory spikes.
How do you implement Secure Network Communication with URLSession and Certificate Pinning?
Implement URLSessionDelegate and validate server public keys or certificates inside didReceive challenge: to prevent Man-in-the-Middle (MITM) proxy attacks.
What is Cassowary Constraint Solver and how does Auto Layout resolve constraints under the hood?
Auto Layout represents UI constraints as a system of linear equations and inequalities. The Cassowary algorithm calculates optimal frame positions (x, y, w, h) by minimizing objective penalty functions.
What is the UIKit View Controller Lifecycle (viewDidLoad, viewWillAppear, viewDidLayoutSubviews)?
loadView: Instantiates the root view • viewDidLoad: Called once when view hierarchy is in memory; ideal for initial setup • viewWillAppear / viewDidAppear: Called every time view transitions onto screen • viewDidLayoutSubviews: Called after Auto Layout computes final subview frames.
How do Apple Push Notifications (APNs) work including Background Push and Notification Service Extensions?
Standard Push: Displays alert, sound, badge • Background Push (content-available: 1): Wakes app silently for up to 30 seconds to fetch fresh content • Notification Service Extension: Intercepts encrypted push payloads before display to decrypt media or download attachments.
How do you detect and fix UI Frame Drops (Jank) using the Core Animation Instrument in Xcode?
60 FPS requires rendering a frame in under 16.6ms (8.3ms for 120 FPS ProMotion). Core Animation Instrument highlights: Offscreen-Rendered Yellow: Uncached shadows or corner radius clipping • Color Misaligned Images: Images not scaled to pixel-aligned dimensions.
How do you architect an Offline-First iOS app with SwiftData / Core Data and background synchronization?
Writes are saved immediately to local SwiftData storage with a sync status flag (isPendingSync). Background synchronization services queue and replay operations with idempotency keys upon network recovery.
What is App Thinning, App Slicing, and On-Demand Resources in iOS deployment?
App Store automatically delivers tailored variants of the app containing only the architecture assets (2x vs 3x images) matching the user's specific iPhone model, minimizing download size.
How do you implement biometric authentication with LocalAuthentication (Face ID / Touch ID)?
Use LAContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics). Cryptographic credentials should be saved in Keychain protected by kSecAccessControlBiometryAny.
How does the SwiftUI Attribute Graph and Diffing Engine minimize redraws?
SwiftUI maintains an internal dependency graph of view nodes and state bindings (Attribute Graph). When state mutates, SwiftUI diffs the graph and triggers body evaluation only for views whose direct input dependencies changed.
SwiftUI State Management: `@State`, `@Binding`, and the `@Observable` Macro (iOS 17+).
@State: Manages local, ephemeral view-owned value state • @Binding: Creates a two-way connection to state owned by a parent view without duplicating data • @Observable (Observation Framework in iOS 17+): Replaces verbose ObservableObject and @Published • Uses Swift Macros to track property access at runtime.
SwiftData Architecture: `@Model`, `ModelContext`, `ModelContainer`, and schema migrations.
SwiftData is Apple's modern persistence framework replacing complex Core Data boilerplate with native Swift macros.
Combine Framework vs AsyncAlgorithms / AsyncSequence: Modern migration strategies.
Combine: Functional reactive framework introduced in iOS 13 using Publisher / Subscriber chains and operators (debounce, flatMap, combineLatest) • AsyncSequence & AsyncAlgorithms (Modern Swift): Replaces complex Combine pipelines with clean, imperative async/await syntax.
UIKit to SwiftUI Interoperability: `UIViewRepresentable` and `UIViewControllerRepresentable` with Coordinators.
Wrapping complex legacy UIKit views (like MKMapView or WKWebView) inside modern SwiftUI: makeUIView(context:): Instantiates and returns the underlying UIKit view • updateUIView(uiView, context:): Updates the UIKit view configuration when SwiftUI state properties change.
Dynamic Island & Live Activities: ActivityKit, WidgetKit extensions, and APNs pushes.
Displaying real-time glanceable updates (ride tracking, food delivery) on the iPhone lock screen and Dynamic Island: ActivityKit: Manages the lifecycle of the activity • WidgetKit UI: Renders the Dynamic Island views in 4 configurations: Compact Leading, Compact Trailing, Minimal, and Expanded.
iOS Memory Management & Out of Memory (OOM) Jetsam Crashes.
iOS does not have virtual memory swap space on disk. If physical RAM runs low: The OS kernel issues memory pressure warnings (applicationDidReceiveMemoryWarning) • If memory continues climbing past the hard footprint limit, the kernel's Jetsam daemon terminates the app with EXCRESOURCE (RESOURCETYPE_MEMORY).
Background Execution Modes: `BGTaskScheduler`, Audio, and Location updates.
iOS strictly restricts background execution to preserve user battery: BGAppRefreshTask: Short execution window (up to 30 seconds) scheduled by the OS when the user is likely to open the app • BGProcessingTask: Long-running maintenance tasks (database cleanup, ML model training) executed only when the device is idle, connected to.
Core Animation Render Pipeline: Commit transaction, Render Server, and Offscreen Rendering.
How pixels reach the iPhone display hardware: Commit Transaction: App prepares view layers and sends serialized hierarchy to the out-of-process Render Server (backboardd) • GPU Drawing: The GPU computes shaders and draws layers into the frame buffer.
Deep Linking Architecture: Universal Links vs Custom Schemes, and `apple-app-site-association`.
Custom Schemes (myapp://path): Insecure and can be claimed by rogue apps installed on the device • Universal Links (https://myapp.com/item/101) • Secure two-way verification: Apple servers fetch https://myapp.com/.well-known/apple-app-site-association containing your Team ID and App Bundle ID.
In-App Purchases (IAP) & StoreKit 2: `Product.purchase()` and cryptographic JWS verification.
Apple's modern StoreKit 2 API simplifies purchases using native async/await.
iOS Modular Architecture: Frameworks vs Swift Packages and Dynamic vs Static Linking.
Static Linking (.a / Static Framework): Code is copied directly into the main app executable at compile time • Faster app launch time (zero dyld dynamic loader overhead) • Slightly larger binary size if code is duplicated across extensions • Dynamic Linking (.dylib / Dynamic Framework): Linked at runtime by dyld.
Security in iOS: App Transport Security (ATS) and Keychain Services API.
App Transport Security (ATS): Enforces TLS 1.3 with forward secrecy for all HTTP network connections initiated via URLSession • Keychain Services: Stores sensitive cryptographic keys and passwords in hardware-encrypted partitions • Accessible only when device is unlocked (kSecAttrAccessibleWhenUnlocked).
Accessibility (a11y) in iOS: VoiceOver traits and Dynamic Type scaling.
Building inclusive iOS applications: Dynamic Type: Automatically scales typography using system text styles (.body.headline) • VoiceOver: Annotate views with accessibility traits (button, selected, header), descriptive labels (accessibilityLabel), and actionable hints.
Xcode Instruments Deep Dive: Time Profiler, Leaks, and Allocations.
Essential performance diagnostic workflows: Time Profiler: Samples call stacks at 1ms intervals, highlighting CPU hotspots and heavy background thread functions on a timeline • Allocations: Tracks heap memory allocations over time • Leaks: Detects orphaned memory blocks that are no longer referenced by any pointer in the app.
App Launch Time Optimization: Pre-main (`dyld`) vs Post-main.
Achieving a sub-400ms launch time: Pre-Main Time: The time spent before main() executes • Minimize dynamic framework dependencies (merge into static libraries) • Eliminate C++ static initializers and Objective-C +load methods (replace with +initialize) • Post-Main Time: Time spent inside application(_:didFinishLaunchingWithOptions:).