Open Eradash opened 5 years ago
@Eradash thanks for the effort. I think you should use this in swift only. You can use it by creating by the following:
@objc
.:)
The problem comes with the callback... The method can't be marked with @objc
with this parameter. With the protocol
, it's possible to have the Objective-C support easily in the library.
I can't change all my project to swift, that's why I adapted this library. Feel free to close this PR if it's not appropriate ;)
@Eradash can you please show how you're calling the library function from your objective c? I will give it a try to solve it.
My class is implementing the new protocol
, so the biometricResultOK
and biometricError
are defined (for the callback). I simply call the authentication method of the library with self
as the callback class.
- (void)biometricResultOK {
}
- (void)biometricErrorWithError:(enum AuthenticationErrorOBJC)error {
}
- (void)authenticate:(UITapGestureRecognizer *)gesture {
[BioMetricAuthenticator authenticateWithPasscodeWithReason:@"Test" cancelTitle:@"Cancel test" completion:self];
}
@Eradash why do you want to go with the protocol approach? when you already have a complete block with success or failure?
I agree that may be swift completion with result type is not accessible from the objc, but ideal approach should be making an extension in swift and open a menu from it.
Converting or making it reverse compatible with objc is not a good solution though. Project build time will increase when you increase the conversion to/from with objc/swift.
I'm quite new to Objective C and Swift, and this solution was the fastest and easiest way for me to make the library works
import BiometricAuthentication
extension ViewController {
@objc func presentBiometricAuthentication() {
// swift code here (check the example)
}
This will create a real mess in every project in objc that wants to implement your library. It creates a other file were code can be, and debugging and maintainability are affected. I don't intend to make the switch to Swift in my project, and I think I'm not the only one only for a library. That's why I proposed the solution to make the library compatible with objc. This way, someone can simply import the library, and use it easily in the objc code. I agree it's not the ideal solution. I don't know how to make a proper callback compatible with objc and swift. I proposed my changes to help other dev stuck with objc, and maybe someone knows how to make the library more efficient with objc easily ;)
I needed to use this library inside an Objective-C project. This is the modifications I've done to make it work.