iOS Development IOS App Developer 3 — Questions and Answers
Question 1: Which SwiftUI container arranges child views vertically?
- HStack
- VStack (Correct answer)
- ZStack
- Group
Correct answer: VStack
VStack stacks its child views top to bottom.
Question 2: What is the purpose of the Codable protocol in Swift?
- To enable encoding and decoding to formats like JSON (Correct answer)
- To make a type thread-safe
- To enable UI animations
- To handle Core Data migrations
Correct answer: To enable encoding and decoding to formats like JSON
Codable combines Encodable and Decodable for serialization to and from formats such as JSON.
Question 3: In MVVM architecture, what is the primary responsibility of the ViewModel?
- Rendering pixels to the screen
- Holding presentation logic and state for the view (Correct answer)
- Managing the database schema
- Configuring the build settings
Correct answer: Holding presentation logic and state for the view
The ViewModel exposes presentation state and logic, decoupling the view from the model.
Question 4: Which Xcode tool helps you detect memory leaks and performance issues at runtime?
- Interface Builder
- Instruments (Correct answer)
- Simulator
- Asset Catalog
Correct answer: Instruments
Instruments profiles apps for leaks, allocations, time, and other runtime metrics.
Question 5: What does the @Published property wrapper require its enclosing type to conform to?
- Codable
- ObservableObject (Correct answer)
- Identifiable
- Hashable
Correct answer: ObservableObject
@Published is used inside an ObservableObject to emit changes to subscribers.
Question 6: Which method is called when a view controller's view is about to appear on screen?
- viewDidLoad
- viewWillAppear (Correct answer)
- loadView
- didReceiveMemoryWarning
Correct answer: viewWillAppear
viewWillAppear(_:) is invoked each time before the view becomes visible.
Question 7: What is the recommended way to persist a small amount of user preference data, like a toggle setting?
- UserDefaults (Correct answer)
- Core Data
- A remote server
- URLSession cache
Correct answer: UserDefaults
UserDefaults is designed for lightweight key-value preference storage.
Which SwiftUI container arranges child views vertically?