DEV Community

Pavnesh Kumar
Pavnesh Kumar

Posted on

Answer: How to use completionHandler Closure with return in Swift?

func checkPassword(pass:String,com:@escaping(Bool)-> Void){
    if pass.count < 5{
        com(false)
    }else{
        com(true)
    }
}

let password = "test@1"

checkPassword(pass:password ) { (status) in
    if status{
        print("Strong Password")
    }else{
        print("weak Password")
    }
}

Output###

Strong Password

Discussion (0)