Anyline / anyline-ocr-examples-ios

Example configurations of the Anyline OCR SDK.
https://anyline.com
Other
49 stars 12 forks source link

Setup License Key in Swift does not recognize the BOOL return value #21

Closed StefaniOSApps closed 3 years ago

StefaniOSApps commented 3 years ago

I am currently rewriting a project from Obj-C to Swift. I noticed that I cannot read the success of the "setup license key". Could you please provide a public var that can read out the success?

do {
  let success: Bool = try AnylineSDK.setup(withLicenseKey: licenseKey)
} catch {
  .. handle error
}
Info

suggestion:

do {
  try AnylineSDK.setup(withLicenseKey: licenseKey)
  let success: Bool = AnylineSDK.isConfiguredSuccessfully
} catch {
  .. handle error
}

Many Thanks. You are doing a good job :-)

danielalbertini commented 3 years ago

Hi,

thank you noticing this issue. We are working on a fix for the next release.

As a workaround basically in every case where this "success: Bool" would return false a exception will be thrown and you will land in the catch block and in every case where the Bool would return true no exception will be thrown.

Best regards, Daniel

danielalbertini commented 3 years ago

One more follow up here. After digging into it, I have to say that this is expected behaviour in swift 5.

The original objective-c setup method signature is the following:

+ (BOOL)setupWithLicenseKey:(NSString*)licenseKey error:(NSError**)error;

The generated swift 5 method signature is:

class func setup(withLicenseKey licenseKey: String) throws

So the NSError and BOOL pattern in Objective-C get converted into a throws and void method, as explained in the previous answer the BOOL return would either be always true or not reached.