Top 30 iOS & Swift Concepts Quiz
30 multiple-choice questions on the iOS & Swift fundamentals, drawn from 30 bites in the iOS & Swift library. Answer them here or read straight down. Every question carries the correct option, why it is correct, and a link to the bite it came from.
SwiftUI, UIKit, Xcode, Swift language, Apple platforms
30 questions. Pick an answer, or open “Show the answer” to read it.
Answers are graded in your browser. Nothing is saved, and no XP or streak is earned here. The app keeps score.
Question 1 of 30
A Swift function tries to compile the line let total = 0 followed later in the same function by total = total + 10. What happens?
Show the answer
Answer: c · It fails to compile, because let creates a constant that can only be assigned once, and the second line attempts a second assignment
let enforces single assignment for any type, value or reference, and the compiler catches a second assignment as an error before the program ever runs. Option A is wrong because the let versus var distinction is unrelated to value versus reference semantics, and option C is wrong because Swift never silently ignores a reassignment, it is a hard compile error.
Question 2 of 30
What is the main benefit of using control flow statements like if and for in Swift?
Show the answer
Answer: c · They allow a program to make decisions and repeat specific actions.
Control flow statements are essential because they enable programs to make decisions based on conditions and to repeat blocks of code, moving beyond a simple linear execution. While they can help structure logic to avoid errors, their primary role isn't automatic error fixing or direct speed optimization.
Read the full bite: Swift Control Flow: Directing Your Code's Path
Question 3 of 30
What is the fundamental mechanism by which Swift Optionals prevent runtime crashes from missing values?
Show the answer
Answer: d · They require explicit checks for nil values at compile time, making absence part of the type.
The card states Optionals make "the potential absence of a value an explicit part of its type system, forcing developers to handle the 'nil' case at compile time." This explicit handling prevents runtime crashes by ensuring nil is addressed before code execution. Force-unwrapping (option C) is explicitly mentioned as an anti-pattern that causes crashes if the value is nil, not prevents them.
Read the full bite: Swift Optionals: Handling Nothing Safely
Question 4 of 30
When should a developer generally prefer using a Swift struct over a class for a new data type?
Show the answer
Answer: b · When the data is simple, self-contained, and changes to a copy should not affect the original.
Structs are value types, meaning they are copied on assignment, and changes to the copy do not affect the original. This makes them suitable for simple, self-contained data where independent copies are desired. Classes are used for shared identity and inheritance, and are managed by ARC.
Read the full bite: Swift Structs vs. Classes: Value vs. Reference Types
Question 5 of 30
You add a new case to a widely-used enum. When does this silently undermine compile-time safety?
Show the answer
Answer: b · When switches over the enum include a default clause
A default clause catches the new case automatically, so the compiler cannot force you to handle it explicitly. Omitting a default clause produces a build error for unhandled cases, which preserves compile-time safety.
Question 6 of 30
Which scenario best justifies using Swift's explicit error handling system (with "throws" and "do-catch")?
Show the answer
Answer: d · For operations that can fail in various ways, requiring the caller to understand the specific type of failure to recover.
The card states Swift's error handling is for "recoverable errors where the caller needs context about what went wrong." Option D directly reflects this, emphasizing the need for specific failure context. Option A is incorrect because the card advises using optionals for simple binary success/failure without extra context.
Read the full bite: Swift Error Handling: Throwing, Catching, and Propagating
Question 7 of 30
In performance-critical Swift code, why is 'some Protocol' generally preferred over 'any Protocol'?
Show the answer
Answer: b · It guarantees a specific, consistent concrete type at compile time, enabling static dispatch and avoiding existential container overhead.
The card states that 'any Protocol' incurs performance costs due to dynamic dispatch and potential heap allocation for its existential container. 'some Protocol' avoids this by promising a specific concrete type at compile time, allowing for static dispatch and better performance. Option C is incorrect because protocols do not define stored properties; that is a feature of concrete types or class hierarchies.
Read the full bite: Protocols: Swift's Blueprint for Behavior
Question 8 of 30
What is the primary issue that "weak" or "unowned" references are designed to resolve in Swift's ARC?
Show the answer
Answer: b · Preventing memory leaks caused by two class instances holding strong references to each other.
The card states that `weak` or `unowned` references are used "To break these cycles" which occur "when two class instances hold strong references to each other, preventing either from ever being deallocated," leading to memory leaks. While `weak`/`unowned` help with deallocation, their primary role is to resolve the specific problem of strong reference cycles, not general unreachability.
Read the full bite: Automatic Reference Counting (ARC): Swift's Memory Manager
Question 9 of 30
What is the fundamental behavior of the "await" keyword within an "async" function in Swift?
Show the answer
Answer: d · It suspends the current task, allowing the system to use the thread for other pending work.
The "await" keyword suspends the current task, returning the thread to the system to perform other work until the awaited operation completes. It does not block the thread, which is a common misconception.
Read the full bite: async/await: Write Concurrent Code That Reads Synchronously
Question 10 of 30
When a struct and a class instance are independently passed to functions that modify them, which statement accurately describes the effect on the original instances?
Show the answer
Answer: b · The original class is modified, but the original struct remains unchanged.
Structs are value types, so passing them to a function creates a copy, and modifications within the function do not affect the original. Classes are reference types, meaning the function receives a reference to the original instance, so changes made through that reference will modify the original object.
Question 11 of 30
When is the Swift Result type most advantageous for handling failable operations?
Show the answer
Answer: d · When an asynchronous operation needs to explicitly communicate either a success value or a specific error.
The Result type shines in asynchronous programming, providing a standard and type-safe way to pass either a success value or a specific error, especially when errors cannot be propagated with 'throws' across completion handler boundaries. Option A is incorrect because 'throws' is generally preferred for synchronous functions.
Read the full bite: The Result Type: Modeling Success and Failure
Question 12 of 30
Consider a protocol with a default method implementation provided by a protocol extension. If a type conforming to this protocol also implements that same method, which version will be executed?
Show the answer
Answer: d · The type's specific implementation will be executed, taking precedence over the default.
The card explicitly states: "If the conforming type provides its own implementation for a method, the type's specific version is called at runtime, overriding the default." This allows for customization while still providing a fallback. Option A is incorrect because the type's specific implementation takes precedence.
Read the full bite: Protocol Extensions: Default Behavior for Free
Question 13 of 30
In Swift, when is using a capture list with `self` most critical to prevent a retain cycle?
Show the answer
Answer: b · When a closure is stored as a property of a class instance and references `self`.
Option B correctly identifies the scenario where a retain cycle is most likely: when a closure is stored as a property of a class instance and captures `self`. This creates a strong reference from the instance to the closure and from the closure back to the instance. Option A describes a closure that is executed immediately, which does not typically lead to a retain cycle because the closure does not outlive the function call.
Read the full bite: Retain Cycles and Capture Lists in Swift
Question 14 of 30
Two threads hold references to the same Swift array through two variables, a and b, and both threads call a mutating method on their variable at the same time without any lock. What is the risk?
Show the answer
Answer: c · The isKnownUniquelyReferenced check itself is not thread-safe, so concurrent mutation can race and corrupt the shared buffer
Copy-on-write's uniqueness check and buffer swap are not synchronized, so two threads racing through them concurrently can corrupt shared state or crash. Arrays are not automatically thread-safe, there is no internal lock making one mutation block for the other, and this is a runtime hazard the compiler cannot catch.
Question 15 of 30
What is the primary reason to use an associated type within a Swift protocol?
Show the answer
Answer: b · To enable the protocol to refer to a type whose concrete definition is only known by conforming types.
Associated types exist to allow a protocol's blueprint to refer to a type that is not known until a concrete type adopts the protocol, making the protocol generic over types it uses. Option C is a tempting distractor because, while desirable, the card explicitly states that protocols with associated types cannot be used directly as concrete types for variables or collections without workarounds.
Read the full bite: Associated Types: Making Protocols Generic
Question 16 of 30
What is the primary advantage of using a key path over direct dot notation for property access?
Show the answer
Answer: d · It allows for dynamic, type-safe referencing of properties in generic contexts.
Key paths are designed to pass a type-safe reference to a property itself, enabling generic APIs and dynamic access without losing compile-time safety. Direct dot notation is generally more performant for simple, known property access, making option B incorrect. Key paths enforce type safety, disproving option C, and they refer to the property's location, not its value, making option A incorrect.
Read the full bite: Key-Path Expressions: Type-Safe Pointers to Properties
Question 17 of 30
What is the primary advantage of using an opaque type (e.g., some Collection) as a function's return type?
Show the answer
Answer: b · It provides flexibility to change the underlying implementation without breaking client code.
Opaque types hide the concrete return type behind a protocol, allowing the API provider to change the underlying implementation (e.g., from one collection type to another) without affecting client code that only depends on the protocol. Option A is incorrect because a function with an opaque return type must always return the exact same concrete type. Option D is incorrect because the 'opaque' nature means the client only sees the protocol's capabilities, not the concrete type's unique methods.
Read the full bite: Opaque Types: Hide Implementation, Not Capabilities
Question 18 of 30
Why do type errors in result builder code sometimes reference compiler-generated boilerplate instead of the original developer code?
Show the answer
Answer: d · Because the compiler performs a silent source-to-source rewrite into static method calls during type checking, and errors are reported against the generated code.
The card describes result builders as a compile-time source-to-source rewrite into static method calls, so type errors surface on the generated boilerplate rather than the original code. Distractor A incorrectly attributes the transformation to runtime metaprogramming, when the card explicitly states the rewrite happens during type checking.
Question 19 of 30
Which statement accurately describes the primary role of an Xcode project?
Show the answer
Answer: d · It acts as a central blueprint, organizing references to all files, build settings, and instructions needed to build an app.
An Xcode project serves as a central repository that organizes references to all necessary files, build settings, and instructions for building an app, acting as its blueprint. It does not directly contain all files within the .xcodeproj file, nor is it solely a text editor or just for App Store deployment.
Read the full bite: Xcode Project: Your App's Blueprint and Toolbox
Question 20 of 30
What is the primary advantage of using Interface Builder for UI development?
Show the answer
Answer: d · It enables visual design and arrangement of UI components, accelerating layout.
Interface Builder's main benefit is its visual approach to UI design, allowing developers to quickly lay out screens without writing extensive layout code. While it connects to code, it does not remove the need for code files or automatically generate all UI logic, and programmatic UI is an alternative method.
Read the full bite: Interface Builder: Visual UI Design for iOS/macOS
Question 21 of 30
What is the primary advantage of using an Asset Catalog for managing images in an iOS application?
Show the answer
Answer: b · It automates the selection and delivery of the correct image variant (e.g., resolution, appearance) for the current device context.
The card emphasizes that Asset Catalogs solve the "chaos of managing multiple versions" by automatically serving "the perfect version for the current context" (B). While assets are compiled into an optimized format, the primary advantage is the intelligent management and automatic selection of different variants, not just compression (C). Options A and C describe scenarios explicitly mentioned as "when not to use it" for Asset Catalogs.
Read the full bite: Asset Catalogs: Your App's Smart Media Library
Question 22 of 30
To manage distinct API endpoints for development, staging, and production environments in an Xcode project, what is the recommended approach?
Show the answer
Answer: c · Define custom Build Configurations for staging and production, then create Schemes that specify which configuration to use for each environment's actions.
Custom Build Configurations are designed for managing environment-specific details like API endpoints, and Schemes then link these configurations to specific actions. The card explicitly warns against putting environment settings directly into a Scheme, as that is a common pitfall.
Question 23 of 30
Which statement best describes the fundamental mental model of Auto Layout?
Show the answer
Answer: d · Declaring how UI elements relate to each other through a system of constraints.
Auto Layout's core mental model is about describing relationships between views (e.g., '8 points below the logo') rather than setting fixed frames. Option C describes the manual frame calculation that Auto Layout replaced, making it a tempting but incorrect distractor.
Read the full bite: Auto Layout: Describing Relationships, Not Frames
Question 24 of 30
Under which scenario would using a breakpoint likely be counterproductive for debugging?
Show the answer
Answer: b · Diagnosing a race condition that is highly sensitive to execution timing.
The card states that breakpoints should be avoided for 'issues that are highly timing-dependent, like race conditions,' because pausing the program can alter its behavior and make the bug disappear. The other options describe ideal use cases for breakpoints, such as inspecting variable states or understanding code flow.
Question 25 of 30
Which UI issue is the Xcode View Debugger uniquely suited to diagnose?
Show the answer
Answer: d · A button failing to respond to taps because an invisible view is covering it.
The View Debugger is designed to reveal the visual hierarchy, including invisible views that might be intercepting touches, as highlighted in the canonical example. It is not for debugging application logic (like incorrect text or network issues) or dynamic animations.
Read the full bite: Xcode View Debugger: Uncover Hidden UI Bugs
Question 26 of 30
What is a key advantage of Swift Package Manager compared to previous dependency management tools?
Show the answer
Answer: c · It is a first-party, deeply integrated solution within Xcode.
The card states that Apple created SPM to be a "first-party, officially supported, and deeply integrated way to handle dependencies." The other options describe limitations or common misconceptions, as SPM may not support complex pre-build scripting, can still have version conflicts, and might not work with older, unmaintained libraries.
Read the full bite: Swift Package Manager: Native Dependency Management
Question 27 of 30
Which statement best describes the primary role of an iOS provisioning profile within Apple's security model?
Show the answer
Answer: c · It guarantees that an app can only run on authorized devices, was built by a verified developer, and is allowed specific system capabilities.
The card states provisioning profiles enforce trust by bundling who built the app (certificate), where it can run (devices/App Store), and what it can do (entitlements). Option C accurately summarizes these three core functions. Other options describe security functions not primarily handled by provisioning profiles or misrepresent their verification mechanism.
Read the full bite: iOS Provisioning Profiles: Your App's Passport
Question 28 of 30
Which scenario is Time Profiler LEAST effective at diagnosing as the primary cause of an app's performance issue?
Show the answer
Answer: c · An app becoming unresponsive while awaiting a large network response.
Time Profiler is designed for CPU-bound performance issues, identifying where the CPU spends its time. It is less effective for I/O-bound problems like network waits, where the CPU is idle, as other tools are better suited to show why a thread is waiting.
Read the full bite: Xcode's Time Profiler: Hunting Down Performance Bottlenecks
Question 29 of 30
Which scenario is best suited for using Xcode's Memory Graph Debugger?
Show the answer
Answer: c · Pinpointing the exact objects involved in a strong reference cycle preventing deallocation.
The Memory Graph Debugger is specifically designed to visualize object relationships and identify retain cycles, which are a common cause of memory leaks where objects cannot be deallocated. Other tools like the Time Profiler or Allocations instrument are better suited for general performance or overall memory usage monitoring.
Read the full bite: Hunt Retain Cycles with the Memory Graph Debugger
Question 30 of 30
Which task is explicitly stated as NOT a primary responsibility of a UIView?
Show the answer
Answer: c · Managing application state or performing network operations
The card states that non-visual tasks like network requests, data processing, or managing application state should not live in view code. The other options describe core functions of a UIView.
Could you explain these out loud?
That is what an interview actually tests. Tezvyn gives you questions like these with what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.