0

enter image description here

How to cast this ?

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

enter image description here

1 Answers1

1

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

eemrah
  • 1,603
  • 3
  • 19
  • 37
  • I doubt the second approach is valid. `isPossibleNumber` has no return value in Swift so the use of `if let` won't compile. – HangarRash Dec 14 '22 at 16:54
  • after i've tested it compiled and worked, you can test it after installing with the pods or something else – eemrah Dec 14 '22 at 18:04
  • Did you use the actual Objective-C code or did you make your own version in Swift to test with? The Objective-C method bridged to Swift will not have a `Bool` return value. It will be `Void`. – HangarRash Dec 14 '22 at 18:07
  • after installing it with cocoapods, i've used 2 approach, each of them is above, the situation that you asking returning void for success and throws for another cases – eemrah Dec 14 '22 at 18:10