Bird
0
0

You want to fetch data from multiple URLs concurrently and combine the results. Which approach using TaskGroup is best?

hard📝 Application Q8 of 15
iOS Swift - Concurrency
You want to fetch data from multiple URLs concurrently and combine the results. Which approach using TaskGroup is best?
AUse withTaskGroup to add a task for each URL fetch, then collect and combine results asynchronously
BCreate a single Task that fetches URLs one by one synchronously
CUse multiple Tasks without TaskGroup and combine results immediately
DFetch URLs sequentially inside a TaskGroup without adding tasks
Step-by-Step Solution
Solution:
  1. Step 1: Understand concurrency for multiple fetches

    Using withTaskGroup allows concurrent fetching by adding a task per URL.
  2. Step 2: Combine results after all tasks complete

    Collecting results asynchronously ensures efficient parallel fetching and combination.
  3. Final Answer:

    Use withTaskGroup to add a task for each URL fetch, then collect and combine results asynchronously -> Option A
  4. Quick Check:

    TaskGroup enables concurrent fetch and combine [OK]
Quick Trick: Add a task per URL in TaskGroup for parallel fetch [OK]
Common Mistakes:
  • Fetching URLs sequentially losing concurrency benefits
  • Not using TaskGroup to manage multiple tasks
  • Combining results before tasks finish

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes