CSE 335 EXAM 1 QUESTIONS WITH
ANSWERS AND EXPLANATIONS
1. An app is being revised because of this need: A form view owns a local toggle used only to
control a preview
section. Which change is the best fit?
A. @Binding
B. @Query
C. @Environment
D. @State
Correct Answer: D. @State
Explanation: @State is appropriate for simple transient value state owned by the view itself.
2. During implementation, this requirement arises: A collection transform receives behavior that
should execute for
each element. What should the developer use?
A. A build scheme
B. A module import
C. A property wrapper
D. A closure
Correct Answer: D. A closure
Explanation: Closures are executable blocks that can be passed around and invoked later,
making them useful for callbacks and
higher-order operations.
3. A decoded API record is naturally modeled as a value with no identity-sharing requirement.
Which choice is most
appropriate?
A. A protocol extension only
B. A global singleton
C. A class only
D. A struct
Correct Answer: D. A struct
Explanation: Structs have value semantics and are commonly suitable for lightweight model
values in Swift.
4. During implementation, this requirement arises: A child toggle must change a Boolean owned
by its parent
screen. What should the developer use?
A. @State
B. @Environment
C. @Binding
D. @StateObject
Correct Answer: C. @Binding
Explanation: @Binding lets a child read and write state whose source of truth is owned
elsewhere.
,5. An asynchronous helper reports completion through a callback block. Which choice is most
appropriate?
A. A property wrapper
B. A closure
C. A module import
D. A build scheme
Correct Answer: B. A closure
Explanation: Closures are executable blocks that can be passed around and invoked later,
making them useful for callbacks and
higher-order operations.
6. During implementation, this requirement arises: A preview passes an external observable
model into a reusable
view. What should the developer use?
A. @StateObject
B. @ObservedObject
C. @AppStorage
D. @State
Correct Answer: B. @ObservedObject
Explanation: @ObservedObject is appropriate when an observable object is created elsewhere
and merely observed by this view.
7. An app is being revised because of this need: A shared feature object is constructed above the
current view and
passed in for observation. Which change is the best fit?
A. @StateObject
B. @State
C. @ObservedObject
D. @AppStorage
Correct Answer: C. @ObservedObject
Explanation: @ObservedObject is appropriate when an observable object is created elsewhere
and merely observed by this view.
8. A code review focuses on this situation: A view owns a temporary search string that is
discarded when the view
is recreated. Which design decision best addresses it?
A. @Environment
B. @Query
C. @State
D. @Binding
Correct Answer: C. @State
Explanation: @State is appropriate for simple transient value state owned by the view itself.
9. During implementation, this requirement arises: A filter panel needs a single-choice control for
sort order. What
should the developer use?
A. Divider
B. ProgressView
C. Picker
D. Text
Correct Answer: C. Picker
Explanation: Picker represents selection among a known set of alternatives.
, 10. An app is being revised because of this need: A temporary settings panel should be presented
without pushing
onto the navigation stack. Which change is the best fit?
A. .overlay
B. .sheet
C. .fixedSize
D. .background
Correct Answer: B. .sheet
Explanation: A sheet presents modal content while preserving the underlying screen.
11. A code review focuses on this situation: A network response may contain an optional subtitle
that should be
used only when present. Which design decision best addresses it?
A. Compare the optional to an empty string regardless of type
B. Convert all optionals into global variables
C. Optional binding with if let or guard let
D. Force unwrap every optional
Correct Answer: C. Optional binding with if let or guard let
Explanation: Optional binding safely unwraps a value only when it is non-nil.
12. A location value can be absent until the device has produced its first fix. Which choice is most
appropriate?
A. Convert all optionals into global variables
B. Compare the optional to an empty string regardless of type
C. Optional binding with if let or guard let
D. Force unwrap every optional
Correct Answer: C. Optional binding with if let or guard let
Explanation: Optional binding safely unwraps a value only when it is non-nil.
13. A data-entry screen needs labeled controls with standard platform spacing. Which choice is
most appropriate?
A. LazyHGrid
B. Canvas
C. TimelineView
D. Form
Correct Answer: D. Form
Explanation: Form groups standard data-entry controls in a platform-appropriate
settings/data-entry presentation.
14. During implementation, this requirement arises: A search result should open a detail
destination while
preserving prior navigation history. What should the developer use?
A. NavigationStack
B. GeometryReader
C. ZStack
D. Form
Correct Answer: A. NavigationStack
Explanation: NavigationStack provides stack-based value-driven navigation in modern SwiftUI.
15. A code review focuses on this situation: A profile editor lets the user choose one value from a
defined
enumeration. Which design decision best addresses it?
A. Picker
B. Text
C. ProgressView
D. Divider
Correct Answer: A. Picker
Explanation: Picker represents selection among a known set of alternatives.
ANSWERS AND EXPLANATIONS
1. An app is being revised because of this need: A form view owns a local toggle used only to
control a preview
section. Which change is the best fit?
A. @Binding
B. @Query
C. @Environment
D. @State
Correct Answer: D. @State
Explanation: @State is appropriate for simple transient value state owned by the view itself.
2. During implementation, this requirement arises: A collection transform receives behavior that
should execute for
each element. What should the developer use?
A. A build scheme
B. A module import
C. A property wrapper
D. A closure
Correct Answer: D. A closure
Explanation: Closures are executable blocks that can be passed around and invoked later,
making them useful for callbacks and
higher-order operations.
3. A decoded API record is naturally modeled as a value with no identity-sharing requirement.
Which choice is most
appropriate?
A. A protocol extension only
B. A global singleton
C. A class only
D. A struct
Correct Answer: D. A struct
Explanation: Structs have value semantics and are commonly suitable for lightweight model
values in Swift.
4. During implementation, this requirement arises: A child toggle must change a Boolean owned
by its parent
screen. What should the developer use?
A. @State
B. @Environment
C. @Binding
D. @StateObject
Correct Answer: C. @Binding
Explanation: @Binding lets a child read and write state whose source of truth is owned
elsewhere.
,5. An asynchronous helper reports completion through a callback block. Which choice is most
appropriate?
A. A property wrapper
B. A closure
C. A module import
D. A build scheme
Correct Answer: B. A closure
Explanation: Closures are executable blocks that can be passed around and invoked later,
making them useful for callbacks and
higher-order operations.
6. During implementation, this requirement arises: A preview passes an external observable
model into a reusable
view. What should the developer use?
A. @StateObject
B. @ObservedObject
C. @AppStorage
D. @State
Correct Answer: B. @ObservedObject
Explanation: @ObservedObject is appropriate when an observable object is created elsewhere
and merely observed by this view.
7. An app is being revised because of this need: A shared feature object is constructed above the
current view and
passed in for observation. Which change is the best fit?
A. @StateObject
B. @State
C. @ObservedObject
D. @AppStorage
Correct Answer: C. @ObservedObject
Explanation: @ObservedObject is appropriate when an observable object is created elsewhere
and merely observed by this view.
8. A code review focuses on this situation: A view owns a temporary search string that is
discarded when the view
is recreated. Which design decision best addresses it?
A. @Environment
B. @Query
C. @State
D. @Binding
Correct Answer: C. @State
Explanation: @State is appropriate for simple transient value state owned by the view itself.
9. During implementation, this requirement arises: A filter panel needs a single-choice control for
sort order. What
should the developer use?
A. Divider
B. ProgressView
C. Picker
D. Text
Correct Answer: C. Picker
Explanation: Picker represents selection among a known set of alternatives.
, 10. An app is being revised because of this need: A temporary settings panel should be presented
without pushing
onto the navigation stack. Which change is the best fit?
A. .overlay
B. .sheet
C. .fixedSize
D. .background
Correct Answer: B. .sheet
Explanation: A sheet presents modal content while preserving the underlying screen.
11. A code review focuses on this situation: A network response may contain an optional subtitle
that should be
used only when present. Which design decision best addresses it?
A. Compare the optional to an empty string regardless of type
B. Convert all optionals into global variables
C. Optional binding with if let or guard let
D. Force unwrap every optional
Correct Answer: C. Optional binding with if let or guard let
Explanation: Optional binding safely unwraps a value only when it is non-nil.
12. A location value can be absent until the device has produced its first fix. Which choice is most
appropriate?
A. Convert all optionals into global variables
B. Compare the optional to an empty string regardless of type
C. Optional binding with if let or guard let
D. Force unwrap every optional
Correct Answer: C. Optional binding with if let or guard let
Explanation: Optional binding safely unwraps a value only when it is non-nil.
13. A data-entry screen needs labeled controls with standard platform spacing. Which choice is
most appropriate?
A. LazyHGrid
B. Canvas
C. TimelineView
D. Form
Correct Answer: D. Form
Explanation: Form groups standard data-entry controls in a platform-appropriate
settings/data-entry presentation.
14. During implementation, this requirement arises: A search result should open a detail
destination while
preserving prior navigation history. What should the developer use?
A. NavigationStack
B. GeometryReader
C. ZStack
D. Form
Correct Answer: A. NavigationStack
Explanation: NavigationStack provides stack-based value-driven navigation in modern SwiftUI.
15. A code review focuses on this situation: A profile editor lets the user choose one value from a
defined
enumeration. Which design decision best addresses it?
A. Picker
B. Text
C. ProgressView
D. Divider
Correct Answer: A. Picker
Explanation: Picker represents selection among a known set of alternatives.