Marc
05/31/2024, 12:03 PMIosSwiftWrapper
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
language = Objective-C
depends = Foundation
package = IosSwiftWrapper
modules = IosSwiftWrapper
and added
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?