Prepare for Swift/iOS interviews with 45+ questions on language features, SwiftUI, and app architecture.
Structs: value types (copied on assignment), stack allocated, no inheritance, memberwise initializer. Classes: reference types (shared), heap allocated, support inheritance, deinit available. Use structs for: data models, small values, when you want copies. Use classes for: shared state, inheritance needs, Objective-C interop. Swift favors structs (safer, faster).
Optionals represent values that may be nil. Unwrapping: if let (optional binding), guard let (early exit), nil coalescing (??), force unwrap (! - avoid). Optional chaining (?.) for nested optionals. Implicitly unwrapped optionals (!) for values set after init. Best practice: prefer optional binding, avoid force unwrapping except in tests/IBOutlets.
Protocols define interface contracts (methods, properties). Protocol extensions add default implementations. Protocol-oriented: prefer composition over inheritance, use protocols as types. Benefits: flexibility, testability, multiple conformance. Key patterns: protocol with associated type, protocol composition (&), conditional conformance. Swift standard library is protocol-heavy.
ARC (Automatic Reference Counting) tracks references to class instances, deallocates when count reaches zero. Strong references increase count. Weak references (weak var) don't increase count, become nil when object deallocates. Unowned references assume object exists (crash if wrong). Use weak for delegates, closures capturing self. Avoid retain cycles.
SwiftUI: declarative UI framework, describe what UI should look like, automatic updates. UIKit: imperative, tell iOS how to build UI step by step. SwiftUI benefits: less code, previews, cross-platform (iOS, macOS, watchOS). Limitations: iOS 13+, some missing features. Modern apps: SwiftUI for new views, UIKit for complex/legacy features. Use UIViewRepresentable for bridging.
Practice with interactive quizzes and get instant feedback.
Start Free Practice