Hi all, looking for guidance on integrating a loca...
# compose-ios
j
Hi all, looking for guidance on integrating a local .xcframework library into a Compose Multiplatform iOS project. Any tips or best practices?
p
Drag and drop into Xcode/embedded libraries and framework is the standard way or Xcode has another way. You have to commit the binary to your repo if planning CI/CD
j
Now how to call it in kotlin?
p
I don't think kotlin will generate language bindings for a third party iOS library. It has bindings for Apple packages but I don't think it will generate objc headers automatically. Maybe there is a task for it, I am not aware. What I do is use interfaces to bridge between the code in iosMain and Swift.
These interfaces are implemented in swift side and provided to the ComposeUiViewController via constructor. Or you can use global factory functions with expect/actual
j
If the .xcframework is published with CocoaPods, the Kotlin/Native CocoaPods Gradle plugin will generate C interop for you. But you can also do this manually with a local .xcframework. The docs describe doing this for a C library, but it works similarly for Objective-C. You need to define a .def file, by default located in src/nativeInterop/cinterop. It'll be something like this:
Copy code
language = Objective-C
modules = ModuleName
linkerOpts = -framework FrameworkName
Then configure the C interop for the compilation. Something like this:
Copy code
targets.withType<KotlinNativeTarget>().configureEach {
    if (konanTarget.family.isAppleFamily) {
        val main by compilations.getting
        main.cinterops.create("defFileName") {
            includeDirs("path/to/framework/headers")
        }
    }
}
👍 1
You may also need to set up linking the framework during binary compilation. Within each native target (may vary by architecture the path to the .framework within the .xcframework), something like this:
Copy code
binaries.framework {
    val path = "$rootDir/path/to/framework/FrameworkName.xcframework/target-arch"
    linkerOpts("-F$path", "-framework", "FrameworkName", "-rpath", path)
}
🙌 1
p
Thanks Jeff good to know
👍🏼 1