https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

adev_one

08/27/2018, 1:21 PM
I’m trying to implement something like
UI
dispatcher from anko but on iOS My
build.gradle
Copy code
buildscript {
    ext.kotlin_version = '1.2.51'
    ext {
        coroutines_version = "0.25.0"
    }
}

apply plugin: 'kotlin-platform-native'

sourceSets {
    main {
        component {
            baseName.set("NF")
            outputKinds = [FRAMEWORK]
            target 'ios_arm64', 'ios_x64'//, 'ios_arm32'
        }
    }
}

dependencies {
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
    <...>
}
IosDisplayContext.swift
Copy code
import NF

@objc
class IosDisplayContext: NSObject, NFCoroutineDispatcher {

}
I’m getting error
Use of undeclared type 'NFCoroutineDispatcher'
. How can I implement public protocols of coroutines library by my Swift code?
e

elizarov

08/27/2018, 2:10 PM
You cannot. They are not exposed to Swift. You need to implement it in Kotlin, then compile the result (kotlinx.coroutines + your code) into a Swift framework for use in your Swift app.
4 Views