Skip to main content

Cinterop

SKIE cannot directly generate code that uses types provided by custom cinterop bindings. The problem with these types is that SKIE doesn't know what framework will provide their implementation at runtime. Therefore, the correct framework names must be manually configured using the SKIE configuration. However, providing the framework name is only necessary if you need to use the generated declarations with those types.

note

Built-in cinterop bindings work out of the box because SKIE can derive the framework name from the class package.

If the framework name is not provided, SKIE generates a placeholder declaration that cannot be called. However, you can still call the original Kotlin declaration.

Let's take CrashKiOS as an example. It has a module co.touchlab.crashkios:bugsnag, which contains a global function: fun startBugsnag(config: BugsnagConfiguration). The BugsnagConfiguration is a type provided by an external Obj-C framework. Without the framework name configuration, SKIE generates the following function:

Swift generated by SKIE
@available(*, unavailable, message: "Unknown Swift framework for type 'co.touchlab.crashkios.bugsnag.BugsnagConfiguration'. ...")
public func configureBugsnag(config: __SkieUnknownCInteropFrameworkErrorType) {
fatalError("...")
}

If you want to use this function wrapper, you have to configure the framework name like this:

build.gradle.kts
import co.touchlab.skie.configuration.ClassInterop

skie {
features {
group("co.touchlab.crashkios.bugsnag") {
ClassInterop.CInteropFrameworkName("Bugsnag")
}
}
}

Now, SKIE generates the correct function:

Swift generated by SKIE
public func configureBugsnag(config: Bugsnag.BugsnagConfiguration) {
return Kotlin.BugsnagConfigKt.configureBugsnag(config: config)
}