I have a need to expose a newer Swift-only API to ...
# ios
d
I have a need to expose a newer Swift-only API to Kotlin Multiplatform. I understand I will need to write an Objective-C wrapper to re-expose it via ObjC ABI. Can anyone share experience to say if this has been straightforward for them? Any pitfalls or tips with project setup? Thanks!
r
This kind of things makes the recent removal of Swift direct interoperability from the roadmap more and more concerning. More and more libraries are pure Swift, more and more ObjC libs are being deprecated in favor of pure Swift ones. Apple could completely drop support for ObjC at any time for all we know.
âž• 2
đź’Ż 2
d
Agreed @ribesg, this time around it's no toy project either; rather a high value critical business need. Everything else about KMM is fitting beautifully, but this interop looks to be the fly in the ointment. As a Lead I'm basically left assigning a developer to build and maintain the wrapper; AFAIK there's no automated tooling that can take this on.
r
My production app relies on 3 dead ObjC dependencies 👍 Only 3 because I replaced some others with my own…
j
Swift support is removed from the immediate roadmap because of lack of resources. It seems they want to do K2 compiler/ mature new garbage collector first and it needs more research to generate separate namespaces for different Kotlin modules. See the issue: https://youtrack.jetbrains.com/issue/KT-49521/Support-direct-interoperability-with-Swift I think Swift support is essential too, but they had to make some choices to build right foundation first.
đź‘Ť 1
l
Interop with another OO language is quite difficult. Especially something as new as Swift, which only recently stabilized the behaviour under the hood. It would be a very helpful feature, but is very technically challenging.
đź‘Ť 1
Even C++ bidirectional interop is in an extremely early stage. It looks like Apple has a team working on it, but they seem to only be as far as calling C++ from Swift, not the other way around. https://www.infoworld.com/article/3649131/swift-c-plus-plus-interoperability-effort-moves-forward.html
r
How hard it is doesn’t count when it’s required. I think there needs to be clear documentation on the “road to Swift interoperability” somewhere we can link to, because I think the questions about it will be more and more common. Once Apple starts dropping Objective-C support and publishing APIs in Swift only, KMM is done
l
It would probably be more worth the time for the community to create Kotlin versions of the Swift libraries, at least for now. Especially with libraries like Compose.
Is there any indication that Apple will drop Objective-C support in the near future? I can see new libraries being Swift-only if it can make the syntax better (see SwiftUI), but there is still a lot of Obj-C code in the wild. I would imagine JB will re-allocate work in favor of Swift support once K2 is stable, but until then, it’s a monumental effort that likely won’t have any payoff for a while. KMM is still early on, and it’s important that they continue their fast progress right now.
Granted, when Swift support is done, it will have a very large payoff. It will likely take a long time to complete, though.
j
There is no indication Apple will drop Objective-C. Recently in 2020 they did a talk in which they made good advances and stated even in the Platform state of the Union this year they will support the language for many years to come besides libraries like UIKit and Appkit.
Copy code
The Objective-C language, AppKit & UIKit frameworks, and Interface Builder have empowered generations of developers. These technologies were built for each other, and will continue to serve us well for a long time to come, but over time new abstractions become necessary. For a while now, you've seen us hard at work defining the next generation of integrated language, frameworks, and tools: Swift, SwiftUI, and Xcode Previews.
Apple uses Objective-C extensively and as long as full Swift C++ interop is not mature, Objective-C will certainly not deprecated soon.