0
0
Swiftprogramming~10 mins

Task for launching concurrent work in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to launch a concurrent task that prints "Hello".

Swift
Task [1] {
    print("Hello")
}
Drag options to blanks, or click blank then click option'
Arun
Blaunch
Cstart
D()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses after Task
Using incorrect method names like run or start
2fill in blank
medium

Complete the code to launch a task that returns an integer value.

Swift
let task = Task<Int, Never> [1] {
    return 42
}
Drag options to blanks, or click blank then click option'
A()
Bstart
Crun
Dlaunch
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names instead of parentheses
Omitting the parentheses
3fill in blank
hard

Fix the error in the code to correctly launch a task that prints "Done".

Swift
Task [1] {
    print("Done")
}
Drag options to blanks, or click blank then click option'
A()
Bstart()
Claunch()
Drun()
Attempts:
3 left
💡 Hint
Common Mistakes
Adding method calls after Task instead of parentheses
Leaving out parentheses entirely
4fill in blank
hard

Fill both blanks to create a task that returns the sum of two numbers.

Swift
let sumTask = Task<Int, Never> [1] {
    let a = 5
    let b = 7
    return a [2] b
}
Drag options to blanks, or click blank then click option'
A()
B-
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition
Omitting parentheses after Task
5fill in blank
hard

Fill all three blanks to create a task that returns the uppercase version of a string if its length is greater than 3.

Swift
let task = Task<String, Never> [1] {
    let word = "swift"
    if word.count [2] 3 {
        return word.[3]()
    } else {
        return word
    }
}
Drag options to blanks, or click blank then click option'
A()
B>
Cuppercased
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator instead of greater than
Forgetting parentheses after Task or method calls