iOS Development IOS App Developer 2 — Questions and Answers
Question 1: Which property wrapper in SwiftUI creates a source of truth for a value type owned by the current view?
- @State (Correct answer)
- @Binding
- @Environment
- @Published
Correct answer: @State
@State declares a view-owned mutable source of truth for a value type.
Question 2: In a UITableView, which method must you implement to provide the number of rows in a section?
- cellForRowAt
- numberOfRowsInSection (Correct answer)
- didSelectRowAt
- heightForRowAt
Correct answer: numberOfRowsInSection
tableView(_:numberOfRowsInSection:) returns the row count for a given section.
Question 3: What is the default thread on which URLSession completion handlers are called?
- The main thread
- A background thread (Correct answer)
- The thread that started the task
- A serial dispatch queue you specify
Correct answer: A background thread
URLSession delivers completion handlers on a background queue by default, so UI updates must be dispatched to main.
Question 4: Which keyword marks a Swift function that can suspend and resume with structured concurrency?
- throws
- async (Correct answer)
- lazy
- defer
Correct answer: async
The async keyword marks a function that can suspend and be awaited.
Question 5: What does ARC stand for in iOS memory management?
- Automatic Resource Caching
- Automatic Reference Counting (Correct answer)
- Asynchronous Runtime Closure
- Allocated Region Collector
Correct answer: Automatic Reference Counting
Automatic Reference Counting tracks and frees objects when no strong references remain.
Question 6: To avoid a retain cycle in a closure capturing self, which capture list is commonly used?
- [strong self]
- [weak self] (Correct answer)
- [copy self]
- [mutable self]
Correct answer: [weak self]
[weak self] breaks the strong reference cycle by capturing self weakly.
Question 7: Which file declares an iOS app's permissions usage descriptions, like camera access?
- Info.plist (Correct answer)
- AppDelegate.swift
- Package.swift
- Assets.xcassets
Correct answer: Info.plist
Info.plist contains usage description keys required for privacy-sensitive permissions.
Which property wrapper in SwiftUI creates a source of truth for a value type owned by the current view?