I want to write an async-await method with a return value, but my code doesn't work. I also tried another way such as DispatchQueue.global
DispatchGroup()
and so on.
Here is my code:
func checkPassCode() -> Bool {
var result = false
let closure = { (_ flag:Bool) -> Void in
result = flag
}
if var pin = self.keychain.get("pin") {
let userPin = self.pin.joined(separator: "")
let encryptedData = NSData(base64Encoded: pin, options: [])
AsymmetricCryptoManager.sharedInstance.decryptMessageWithPrivateKey(encryptedData! as Data) { (success, result, error) -> Void in
if success {
pin = result!
print("userPin is: \(userPin)")
print("storePin is: \(pin)")
closure(userPin == pin)
} else {
print("Error decoding base64 string: \(String(describing: error))")
closure(false)
}
}
}
return result
}