Three questions from the bank, with answers. The practice test draws different ones each time.
Question 1 · Swift Concurrency · mid
How must the 'getData' function be called?
func getData() async throws -> Data { ... }
A.The caller must use 'try await' to invoke this function.
B.The return type is implicitly converted to an Optional.
C.The function does not need to be called with 'await'.
D.The function must be called on the main thread only.
Show answer
A. The caller must use 'try await' to invoke this function.
'async throws' defines an asynchronous function that can also fail. The caller must use 'try await' to handle both the potential delay and potential error. The trap is forgetting either part of the syntax, causing compiler errors.
Question 2 · SwiftUI List · mid
What is required for the List view to iterate over the 'items' collection?
var body: some View {
List(items) { item in
Text(item.name)
}
}
A.The list will not render because it requires a 'ForEach' inside.
B.'items' elements must conform to 'Identifiable' or be provided an id.
C.The list will crash if 'items' contains duplicate names.
D.'items' must be an array of Strings, not objects.
Show answer
B. 'items' elements must conform to 'Identifiable' or be provided an id.
For the List to efficiently render items, the data collection must conform to 'Identifiable' so SwiftUI can track each row's identity for animations and updates. The trap is forgetting to conform to Identifiable and providing an explicit 'id' key path.
Question 3 · SwiftUI State Management · mid
Which statement correctly describes the behavior of a struct used with @State in SwiftUI?
struct MyViewModel {
let name: String
}
A.The struct must be converted to a class to be used with @State.
B.@State maintains the state of the struct even when the parent view updates.
C.Changes to 'name' will automatically trigger a re-render of the view hierarchy.
D.The struct's properties are automatically observed via key-value observing.
Show answer
B. @State maintains the state of the struct even when the parent view updates.
Since MyViewModel is a struct (a value type), changing it requires replacing the instance. @State creates a persistent store for this value type that survives view updates. The trap is confusing the behavior of value types in SwiftUI vs reference types.