zxingify / zxingify-objc

An Objective-C Port of ZXing
Apache License 2.0
3.07k stars 753 forks source link

Fix swift crash in ZXMultiFormatWriter.m #472

Closed marioradonic closed 5 years ago

marioradonic commented 5 years ago

Hello! I'm using this project in the Swift app. Since it's not possible to catch Objc exceptions in Swift the app crashes when the provided code doesn't pass some validations, eg. when itf code has odd number of digits:

if (length % 2 != 0) {
    [NSException raise:NSInvalidArgumentException format:@"The length of the input should be even"];
}

For a nicer compatibility with Swift I added this small wrapper that bridges nicely to swift so a try catch block in Swift can actually catch the error and handle it.

The tests are still passing, I was thinking about adding a Swift test target to test this, but it looked like an overkill for this simple fix.

Cheers, lemme know if this is alright!

benjohnde commented 5 years ago

Ah perfect, yeah of course this is alright! Thanks a lot for your contribution :) :+1:

marioradonic commented 5 years ago

Thanks for the quick merge @benjohnde ! Do you think it makes sense to bump a version? I can help with another PR if you'd like