Home > front end >  Cannot convert value of type '()' to specified type 'Bool'
Cannot convert value of type '()' to specified type 'Bool'

Time:12-15

enter image description here

How to cast this ?

Cannot convert value of type '()' to specified type 'Bool'

enter image description here

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

  • Related