Closed AndreiVidrasco closed 4 years ago
Hi,
First of all, thank you for such nice words
These lines look like a header from a Swift file generated by an annotation processor. Source code available here: https://github.com/readdle/swift-java-codegen
There is no much documentation yet. But general idea: analyze all Kotlin files with appropriate annotations to generate JNI code for access Swift code from native libraries.
Thank you for fast reply.
So basically, if I understood correctly, I need to write all public apis, that I want to access from swift library, in some kotlin(or Java) form and put annotations on them, and swift-java-codegen will generate such files?
Yes. It's correct
Ok, thank you very much.
Having a tool for auto-generating kotlin files would be amazing in the future, but for now it's already impressive.
Thank you once more
@andriydruk Hi again,
I was wondering, what would be the simplest way of defining and using SwiftBlock from Kotlin?
Right now, based on example from swift-java-codegen, I ended with
@SwiftBlock("(String?) -> Void")
interface AsBlockString {
fun call(update: String?)
}
class AsBlockStringImp(var block: (String?) -> Void) : AsBlockString {
override fun call(update: String?) {
this.block(update)
}
}
with creating and using AsBlockStringImp { println("$it") }
in other parts of the app
which is quite verbose. Do you know maybe of a simpler way?
I believe you can use fun interface from Kotlin 1.4 https://kotlinlang.org/docs/reference/fun-interfaces.html
@SwiftBlock("(String?)->Void")
fun interface AsBlockString {
fun invoke(string: String?)
}
external fun call(@SwiftBlock block: AsBlockString)
fun check() {
call {
print(it)
}
}
Hi,
Amazing example. While browsing through files, I have found several with this remark at the top:
But I couldn't find neither blueprints nor documentation on how to rebuild(regenerate) them.
Can you help me out, on finding some info about it?