-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add support for Swift to Kotlin cases #42
Comments
Some thoughts about Swift implementations of Kotlin classes/interfaces. Kotlin code: interface A {
suspend fun foo(): String
suspend fun bar(): String {
return "Default"
}
}
open class AKotlinImpl: A {
suspend fun foo(): String {
return "Kotlin"
}
}
class AKotlinImplNoDefaults: AKotlinImpl {
override suspend fun bar(): String {
return "Kotlin"
}
}
suspend fun main() {
AKotlinImpl().run {
println(foo()) // Kotlin
println(bar()) // Default
}
AKotlinImplNoDefaults().run {
println(foo()) // Kotlin
println(bar()) // Kotlin
}
} Generated Kotlin code: abstract class ANativeImpl: A {
final override suspend fun foo(): String { /* ... */ }
abstract fun fooNativeImpl(): NativeSuspend<String>
final override suspend fun bar(): String { /* ... */ }
open fun barNativeImpl(): NativeSuspend<String> { /* ... */ }
}
fun A.fooNative(): NativeSuspend<String> { /* ... */ }
fun A.barNative(): NativeSuspend<String> { /* ... */ }
Swift code: class ASwiftImpl: ANativeImpl {
override func fooNativeImpl() -> NativeSuspend<String> {
return nativeSuspend {
return "Swift"
}
}
}
class ASwiftImplNoDefaults: ASwiftImpl {
override func barNativeImpl() -> NativeSuspend<String> {
return nativeSuspend {
return "Swift"
}
}
}
func main() async {
let impl = ASwiftImpl()
print(await asyncFunction(for: impl.fooNative())) // Swift
print(await asyncFunction(for: impl.barNative())) // Default
let implNoDefaults = ASwiftImplNoDefaults()
print(await asyncFunction(for: implNoDefaults.fooNative())) // Swift
print(await asyncFunction(for: implNoDefaults.barNative())) // Swift
} Note: this won't work because Note: this way calling the Swift implementations from Swift will convert from async to |
Just dropping a note to say I too arrived here looking for a library to help with consuming a Swift ASyncStream from Kotlin/Native. |
Me too! Does anything like this exist ? |
Currently the whole library is focused on Kotlin to Swift cases but there are also valid cases for Swift to Kotlin support.
For example you should be able to call the following function from Swift:
https://kotlinlang.slack.com/archives/C3PQML5NU/p1644904527044239
The text was updated successfully, but these errors were encountered: