How to cast this ?
Cannot convert value of type '()' to specified type 'Bool'
CodePudding user response:
As I read the documentation, it's throwable function, so in swift you can use like these ways
guard let instance = NBPhoneNumberUtil.sharedInstance() else { return }
do {
try instance.isPossibleNumber("6766077303", regionDialingFrom: "AT")
print("its valid, continue to process")
} catch {
print("not valid", error)
}
or
guard let instance = NBPhoneNumberUtil.sharedInstance() else { return }
if let _ = try? instance.isPossibleNumber("6766077303", regionDialingFrom: "AT") {
print("its valid number")
} else {
print("there is no validity")
}
If you want to see the error case change AT
with AAT
and see how it works, I would prefer the second usage, so you can establish your logic with if-let
blocks