Skip to content

Add Objective-C support#32

Open
Eradash wants to merge 1 commit into
rushisangani:masterfrom
Eradash:OBJC_Support
Open

Add Objective-C support#32
Eradash wants to merge 1 commit into
rushisangani:masterfrom
Eradash:OBJC_Support

Conversation

@Eradash

@Eradash Eradash commented Aug 14, 2019

Copy link
Copy Markdown

I needed to use this library inside an Objective-C project. This is the modifications I've done to make it work.

@rushisangani

Copy link
Copy Markdown
Owner

@Eradash thanks for the effort.
I think you should use this in swift only.
You can use it by creating by the following:

  • Create a Swift extension
  • Add a method to show the menu, marked in @objc.

:)

@Eradash

Eradash commented Aug 14, 2019

Copy link
Copy Markdown
Author

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 ;)

@rushisangani

Copy link
Copy Markdown
Owner

@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.

@Eradash

Eradash commented Aug 14, 2019

Copy link
Copy Markdown
Author

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];
}

@rushisangani

rushisangani commented Aug 14, 2019

Copy link
Copy Markdown
Owner

@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.

@Eradash

Eradash commented Aug 14, 2019

Copy link
Copy Markdown
Author

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

@rushisangani

Copy link
Copy Markdown
Owner
 import BiometricAuthentication

    extension ViewController {
    
    @objc func presentBiometricAuthentication()  {
      // swift code here (check the example)
    }

@Eradash

Eradash commented Aug 14, 2019

Copy link
Copy Markdown
Author

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 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants