Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the equivalent of koin-annotation in swift code. Leveraging custom swift attributes. #168

Open
pablichjenkov opened this issue Sep 18, 2024 · 1 comment

Comments

@pablichjenkov
Copy link

pablichjenkov commented Sep 18, 2024

Is your feature request related to a problem? Please describe.
One of the techniques to consume third party SDKs in swift from kotlin, consist of:
1- Declare an interface in the kotlin side,
2- Then create a class in swift which conforms to the respective interface(protocol in swift). This class does the actual interaction with the third party SDK.
3- Then we provide these implementations to the koin container bridging the interface implementations typically using a helper class for this.

Another alternative is using global functions that serves as a factory but it kind of pollute the global scope and requires some boilerplate initializing them too.
For reference to the problem you can check this question in stackoverflow:
https://stackoverflow.com/questions/77541454/call-swift-code-from-kotlin-multiplatform

Describe the solution you'd like
I would like to be able to replace the above boilerplate by introducing an annotation that automatically generates, in a specific module, a factory that will bind my swift implementation to my kotlin interface definition. Sort of bellow setup

// kotlin-lang

interface Action {
  fun test()
}
// swift-lang

@KoinBean
public class SwiftAction : Action {
  public init(){}

  public func test() {
    print("Test Passed")
  }
  ...
}

Where "KoinBean" refers to the annotation I am proposing. Which in swift I believe the equivalent is called attributes. This is docs: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/attributes/

Describe alternatives you've considered
The repetitive steps in the above problem description.

Target Koin project
koin-annotation

@pablichjenkov pablichjenkov changed the title Make it possible to use koin-annotation in swift code. Make it possible the equivalent of koin-annotation in swift code. Leveraging custom swift attributes. Sep 18, 2024
@pablichjenkov pablichjenkov changed the title Make it possible the equivalent of koin-annotation in swift code. Leveraging custom swift attributes. Make the equivalent of koin-annotation in swift code. Leveraging custom swift attributes. Sep 18, 2024
@arnaudgiuliani
Copy link
Member

Interesting yes to help connect with Swift

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

No branches or pull requests

2 participants