Browse Questions
- Auto Layout calculates view frames at runtime by solving a system of linear equations defined by your constraints.
- - Serial queue — executes tasks one at a time, in order.
- Use a custom URLProtocol subclass that intercepts URLSession requests and returns fake responses — no network needed, tests run instantly.
- Tasks support cooperative cancellation — you cancel from outside, and the task must check for cancellation and stop itself.
Answer:
- Serial queue — executes tasks one at a time, in order. Second task waits for first to finish.
- Concurrent queue — executes multiple tasks simultaneously on different threads.
Code Example:
// Serial queue — tasks run one after another
let serialQueue = DispatchQueue(label: "com.app.serial")
serialQueue.async { print("Task 1") }
serialQueue.async { print("Task 2") } // always after Task 1
// Concurrent queue — tasks run in parallel
let concurrentQueue = DispatchQueue(label: "com.app.concurrent",
attributes: .concurrent)
concurrentQueue.async { print("Task A") }
concurrentQueue.async { print("Task B") } // may run before Task A
// Global queues are concurrent with different priorities
DispatchQueue.global(qos: .userInitiated).async { ... }
DispatchQueue.global(qos: .background).async { ... }
// Main queue is serial — always use for UI updates
DispatchQueue.main.async {
self.tableView.reloadData()
}