Have any Question?

You can ask below or enter what you are looking for!

Escaping closures

An escaping closure is a closure that is passed to a function as an argument but is called after the the function returns.
This is typically what we need in completion handlers of asynchronous calls.
Closures are non-escaping by default so we define a closure as escaping by adding the keyword @escaping before its type in the function parameters list as follows:

    func apiGetData(x: Int, y: Int, completion: @escaping (Bool) -> ()) {
        
        if x > y {
            completion(false)
        } else {
            completion(true)
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *