is there a way to reference custom code written in...
# multiplatform
m
is there a way to reference custom code written in Swift in the shared module with Kotlin?
👀 1
v
Be more specific, in shared module for ANY target (so just like KMM library) or only for iOS targets.
m
for simplicity let’s say using my Swift code in iOS target module. Then it could be tied to shared module with interface or expect/actual
I’m just wondering about boundries of KMM technology, because I can use Kotlin code in my Swift code and I was wondering if I can do the opposite. I can use ObjC platform code standard lib in Kotlin, but is it possible also with code I write myself
v
I mean, we can use everything from standard iOS library by default. So it is somehow configured. We are currently on proofing the very question. For now we assume it is and very easy. Make a Swift (or objc if swift is not that easy) library, host it and add to cocoapods. I prefer if we can skip host part and just copy-paste the sources in the project, but not sure this is possible yet. I found out a medium topic which explains what you are asking. I am not sure if I am allowed to post medium links here so google for "kotlin multiplatform create a swift library" and you will see the medium post from kodein-koders which explains everything (I think) with the ChachaPoly example
m
thanks so much! I’ll look into it
a
You can, but you will have to create an ObjC-compatible API in Swift as for now there is no direct interop between Swift and Kotlin/Native.
m
thanks for the answer! So if I understand it correctly, using my own code written in ObjC in iOS Kotlin target module is a standard feature of KMM?
a
Kotlin can consume Obj-C frameworks (or bare headers + binary) and CocoaPods dependencies (that can be local). If you aren’t using CocoaPods you’ll have to compile your custom code yourself. Take a look here for more info https://kotlinlang.org/docs/multiplatform-mobile-ios-dependencies.html
m
that’s exactly what I was looking for, thanks a ton!
l
Note that you can also use Swift code annotated with objc. Not all Swift code can be annotated this way.
v
We have learned that topic. Seems easy. We had 3 example libraries sources codes of which we just copy-pasted into our shared/src/iosMain/my_pods folder. Then we added those libraries to cocoapods config with project file path. 1 lib - pure ObjC - works 2 lib - Swift compatible with ObjC - works 3 lib - Pure Swift - doesn't work and we haven't found plans in the roadmap for that. The libraries available in kotlin for iOS source sets via cocoapods. package