Complete the code to declare an async function.
func fetchData() async [1] String { return "Data" }
The arrow -> is used to specify the return type of the function.
Complete the code to call an async function with await.
Task {
let result = try? await [1]()
print(result ?? "No data")
}You call the async function by its name without parentheses inside await.
Fix the error in the async test function declaration.
func testFetch() [1] async throws { let data = try await fetchData() XCTAssertEqual(data, "Data") }
Test functions that call async throwing functions must be marked async throws.
Fill both blanks to create a dictionary comprehension filtering async results.
let filtered = try await Dictionary(uniqueKeysWithValues: results.compactMap { item in guard let value = item.value, value [1] 10 else { return nil } return (item.key, value[2]2) })
The guard checks if value is greater than 10, and the value is multiplied by 2 using *.
Fill all three blanks to create an async test that awaits and asserts a value.
func testValue() async throws {
let value = try await [1]()
XCTAssertEqual(value, [2])
XCTAssertTrue(value [3] 0)
}The function fetchNumber() is awaited, the expected value is "Data", and the test checks if value is greater than 0.
