Anybody using Kotlin as a replacement for Obj-C/Sw...
# kotlin-native
a
Anybody using Kotlin as a replacement for Obj-C/Swift? For example in MPP, where implementation for iOS platform would usually be written in Obj-C/Swift
r
Yes.
a
Any issues or does it works as expected?
r
It depends on what your goal is
You can’t do everything you can do in Swift with Kotlin
Like, we still write our ViewControllers in Swift for easier view building using XCode
But everything else is Kotlin
a
Is the UI part just harder or impossible to use?
r
Last time I checked you had to write .h files manually or something, but I didn’t really try
s
The original kotlin conf app was written in pure kotlin but today it is a hybrid. You could do it all in Kotlin but you'll give up some of the nice tooling integrations Xcode has with Swift/ObjC when creating your app.
r
Until SwiftUI becomes a thing you need the XCode Interface Builder. If you write your view controllers in Kotlin it’s very hard
a
Thanks for the info, sounds good enough to consider it as an option at some point in the future
s
For instance all of your UI would have to be created in code without storyboards. In the iOS world there's a significant minority that would have no problem with that statement as storyboards and interface builder will only get you so far.
a
makes sense, if i understood correctly the hard part is mostly related to tooling and not actually that kotlin can’t access the api/libraries
s
There are some edge cases that you may run into in dealing with delegates methods that have the same type signature but different names for the parameters. ObjC encodes both into the signature whereas Kotlin does not. Example, both of these methods are valid in an ObjC protocol:
Copy code
-(NSInteger) add:(NSInteger) x (NSInteger) y;
-(NSInteger) add:(NSInteger) a (NSInteger) b;
There's a kotlin compiler override to allow a class implementing that interface/protocol to compile. Another slightly less edge case scenario is inheritance. Any Kotlin class inheriting from an ObjC/Swift class will be final. You can't for instance have a BaseUIViewController.kt that your other kotlin classes would inherit from. For more info check out https://github.com/JetBrains/kotlin-native/blob/master/OBJC_INTEROP.md
👍 1