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

Swift overriding a function from commonMain interface #161

Closed
omargda opened this issue Mar 9, 2024 · 2 comments
Closed

Swift overriding a function from commonMain interface #161

omargda opened this issue Mar 9, 2024 · 2 comments

Comments

@omargda
Copy link

omargda commented Mar 9, 2024

Hey!

I have trouble figuring out how I can use this library to help override suspend functions from an interface declared in commonMain of a KMP project.

I am unable to share my entire code, but this is what it generally looks like (for the sections I'm confused on).

Project structure is similar to this:

  • KMP Module
    • shared
    • exampleModuleA
    • exampleModuleB

With the Android and iOS app in their own repos and ingesting the KMP Module as a submodule (in Android) and as a static framework (in iOS).

I have an interface (ExampleManager) in a file (ExampleManager.kt) located in KMPModule/exampleModuleA/commonMain.

import com.rickclephas.kmp.nativecoroutines.NativeCoroutines
import com.example.me.multiplatform.exampleModuleB.extensions.Result

interface ExampleManager {
    @NativeCoroutines
    suspend fun signUp(
        username: String,
        password: String,
        email: String,
    ): Result<Unit, String>

    @NativeCoroutines
    suspend fun accountDoesExist(email: String): Result<Boolean, SignInError>

    fun updateName(name: String)
}

Due to necessary iOS libraries being unable to be used in the KMP Module's commonMain, the implementation of this interface is created in the Android app code and the iOS app code and injected into the commonMain code with Koin.

Example implementation in iOS:

class IOSExampleManager: ExampleManager {
    // overridden functions here
}

I am using KMP-Coroutines version 1.0.0-ALPHA-10 (for Kotlin 1.8.21 compatibility). I see it does generate the functions within a new NativeKt interface, but how may I override this on iOS/Swift to provide the implementation? I have read the README on the interface workaround with the extension (as well as this thread https://github.com/rickclephas/KMP-NativeCoroutines/issues/103), but I'm still confused on how I can override a method from the interface (e.g. signUp). Thanks!

@rickclephas
Copy link
Owner

Hi! At the moment the library only supports Kotlin to Swift cases. Swift to Kotlin cases (like implementing an interface) are still a work in progress. Please keep an eye on #42

@omargda
Copy link
Author

omargda commented Mar 9, 2024

Ah, I see. Thanks for the quick reply and the great work with this library! I'll go ahead and close this and refer to https://github.com/rickclephas/KMP-NativeCoroutines/issues/42.

@omargda omargda closed this as completed Mar 9, 2024
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

No branches or pull requests

2 participants