I'm complety lost with async await operation
I have a subclass of UITextField which provide a verif method in the resignFirstResponder method, I call the verif Method and return true or false, depending of the result of the verif
the verif method is asynchrone, because it can make call to a web server.
My code is:
import UIKit
public enum VerifResult<S: NSString> {
case success
case failure(S)
}
@IBDesignable class TextField: UITextField {
@IBInspectable var obligatoire: Bool = false
override func resignFirstResponder() -> Bool {
var bRes = false
do {
let res = try await withCheckedThrowingContinuation {
continuation in
let result = try await verif()
continuation.resume(returning: result)
}
switch res {
case .success: bRes = true
case .failure(let msg): bRes = false
}
} catch {
return false
}
return bRes
}
public func verif() async throws -> VerifResult<NSString> {
if obligatoire && text == "" {
return .failure("Zone obligatoire")
} else {
// make call to a webserver and return .sucess or .failure
return .success
}
}
}
in the resignFirstResponder on the line try await, the compiler detects the error:
Invalid conversion from throwing function of type '(CheckedContinuation<_, Error>) async throws -> Void' to non-throwing function type '(CheckedContinuation<T, Error>) -> Void'
I'm lost, I don't understand why where is my mistake?