Hi, I'm trying to use a Swift only library from my...
# ios
m
Hi, I'm trying to use a Swift only library from my iOS code. From what I've read, Kotlin doesn't seem to have support for Swift only libraries since when I import the pod directly I only see a handful of constants. I assume the alternative is writing a wrapper library yourself? I am unsure about this step as I am not familiar at all with iOS development. I tried creating a Swift library called
IosSwiftWrapper
in XCode and then writing wrapper functions for the logic I need that are annotated with
@objc
. Then I found an
xcodebuild
command that builds an
.xcarchive
file which somewhere inside contains a
.framework
file, which from what I am seeing is what I need to be able to link it into my Kotlin build. I then defined a
.def
file with the content
Copy code
language = Objective-C
depends = Foundation
package = IosSwiftWrapper
modules = IosSwiftWrapper
and added
Copy code
iosArm64 {
    compilations.getByName("main") {
        val IosSwiftWrapper by cinterops.creating {
            defFile(project.file("IosSwiftWrapper/IosSwiftWrapper.def"))
            compilerOpts("-framework", "IosSwiftWrapper", "-F./IosSwiftWrapper/output/IosSwiftWrapper.xcarchive/Products/usr/local/lib")
        }
    }

    binaries.all {
        linkerOpts("-framework", "IosSwiftWrapper", "-F./IosSwiftWrapper/output/IosSwiftWrapper.xcarchive/Products/usr/local/lib")
    }
}
to my
build.gradle.kts
. This does not actually work though, since cinterop fails with the error
fatal error: module 'IosSwiftWrapper' not found
during a Gradle sync. Is this the correct approach to use the Swift library? If yes, how do I correctly import the wrapper into my Kotlin code?