Complete the code to call the function with a closure that prints "Hello".
func greet(action: () -> Void) {
action()
}
greet [1] {
print("Hello")
}Complete the function parameter to accept a closure that takes an Int and returns an Int.
func modify(number: Int, with closure: [1]) -> Int { return closure(number) }
Fix the error in the closure parameter type to accept a closure that takes two Ints and returns Bool.
func compare(a: Int, b: Int, using predicate: [1]) -> Bool { return predicate(a, b) }
Fill both blanks to create a function that accepts a closure with no parameters and returns a String, then call it.
func fetchMessage(completion: [1]) { let message = completion() print(message) } fetchMessage [2] { return "Done" }
Complete the code to define and call a function that accepts a closure taking a String and returning an Int, then prints the result.
func process(text: String, with closure: [1]) { let length = closure(text) print("Length: \(length)") } process(text: "Swift") { text in return text.count }
