Complete the code to launch a concurrent task that prints "Hello".
Task [1] { print("Hello") }
The Task initializer requires parentheses () to start the concurrent work.
Complete the code to launch a task that returns an integer value.
let task = Task<Int, Never> [1] { return 42 }
The Task initializer requires parentheses () to start the concurrent work and capture the return value.
Fix the error in the code to correctly launch a task that prints "Done".
Task [1] { print("Done") }
The correct way to launch a task is to call Task() with empty parentheses, not with method calls like start().
Fill both blanks to create a task that returns the sum of two numbers.
let sumTask = Task<Int, Never> [1] { let a = 5 let b = 7 return a [2] b }
The task is launched with empty parentheses (). To sum two numbers, use the plus operator +.
Fill all three blanks to create a task that returns the uppercase version of a string if its length is greater than 3.
let task = Task<String, Never> [1] { let word = "swift" if word.count [2] 3 { return word.[3]() } else { return word } }
The task is launched with parentheses (). The condition checks if the length is greater than 3 using >. To convert to uppercase, use the uppercased() method.