Skip to content

Instantly share code, notes, and snippets.

@danailalexiev
Created October 5, 2022 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danailalexiev/0abfa7e9c57c9cf2495a66ebd2773b67 to your computer and use it in GitHub Desktop.
Save danailalexiev/0abfa7e9c57c9cf2495a66ebd2773b67 to your computer and use it in GitHub Desktop.
Kotlin Multiplatform iOS Interop
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