Berlin
Berlin

Reputation: 2227

How to use below closure variable in Swift

I am working on clouser in swift iOS, I have tried to create variable using clouser and add 2 clouser in single variable, variable declaration I did right, but I don't understand how to access it in my code.

here is the variable declaration.

var multipleClouser: ((_ success: (Bool), _ failer:(Error) -> Void)?

Upvotes: 0

Views: 113

Answers (1)

Asperi
Asperi

Reputation: 257693

Most probably you meant callback, like

var multipleClouser: ((_ success: (Bool), _ failer: (Error?)) -> Void)?

and usage, like

multipleClouser?(true, nil)

or

multipleClouser?(false, SomeErrorHere)

set up like

multipleClouser = { success, error in
    if success {
        print("Done!")
    } else {
        print("Failure")
        if let error = error {
            print("\t with error: \(error)")
        }
    }
}

Upvotes: 1

Related Questions