Created
October 5, 2022 07:52
-
-
Save danailalexiev/0abfa7e9c57c9cf2495a66ebd2773b67 to your computer and use it in GitHub Desktop.
Kotlin Multiplatform iOS Interop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface JokeClient { | |
fun getRandomJoke( | |
category: JokeCategory? = null, | |
completionHandler: CompletionHandler<Joke?> | |
): NativeCancellable | |
fun getJokeCategories(completionHandler: CompletionHandler<List<JokeCategory>?>): NativeCancellable | |
fun findJoke( | |
query: String, | |
completionHandler: CompletionHandler<JokeSearchResult?> | |
): NativeCancellable | |
} | |
internal class JokeClientImpl(private val apiClient: ApiClient) : | |
JokeClient { | |
init { | |
freeze() | |
} | |
override fun getRandomJoke( | |
category: JokeCategory?, | |
completionHandler: CompletionHandler<Joke?> | |
) = | |
iosScope.withNativeCompletionHandler(completionHandler) { | |
apiClient.getRandomJoke(category) | |
} | |
override fun getJokeCategories(completionHandler: CompletionHandler<List<JokeCategory>?>) = | |
iosScope.withNativeCompletionHandler(completionHandler) { | |
apiClient.getJokeCategories() | |
} | |
override fun findJoke(query: String, completionHandler: CompletionHandler<JokeSearchResult?>) = | |
iosScope.withNativeCompletionHandler(completionHandler) { | |
apiClient.findJoke(query) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment