Recall & Review
beginner
What is a
Task in Swift concurrency?A
Task represents a unit of asynchronous work that runs concurrently. It allows you to start work that can run independently from the current code flow.Click to reveal answer
beginner
How do you create a new concurrent task in Swift?
You create a new task by calling
Task { ... } and placing asynchronous code inside the closure. This runs the code concurrently.Click to reveal answer
intermediate
What is the difference between
Task and async/await?async/await lets you write asynchronous code that waits for results, while Task launches work concurrently without blocking the current thread.Click to reveal answer
intermediate
How can you cancel a running
Task?You can call
task.cancel() on the Task instance. Inside the task, you should check for cancellation using Task.isCancelled to stop work cooperatively.Click to reveal answer
beginner
What happens if you call
Task { ... } inside a synchronous function?The task starts running concurrently in the background immediately, allowing the synchronous function to continue without waiting for the task to finish.
Click to reveal answer
Which Swift code launches a new concurrent task?
✗ Incorrect
Using
Task { ... } launches a new concurrent task. Option D uses GCD, which is different from Swift concurrency tasks.How do you check if a task has been cancelled inside its code?
✗ Incorrect
Task.isCancelled is a static property to check cancellation inside the task.What does
Task { ... } return?✗ Incorrect
Task { ... } returns a Task instance that you can use to manage the concurrent work.Which statement is true about
Task in Swift concurrency?✗ Incorrect
Task runs code concurrently, allowing the current thread to continue.How can you cancel a running
Task?✗ Incorrect
You cancel a task by calling its
cancel() method.Explain how to launch concurrent work using Task in Swift and how cancellation works.
Think about starting work that runs alongside your current code and how you can stop it if needed.
You got /4 concepts.
Describe the difference between using async/await and launching a Task in Swift concurrency.
Consider when you want to wait for a result versus when you want to start work and continue immediately.
You got /4 concepts.