https://kotlinlang.org logo
Title
d

Denis Shurygin

07/05/2018, 12:30 PM
Does it possible to override Objective-C methods? I found way to call them in this document: https://github.com/JetBrains/kotlin-native/blob/master/OBJC_INTEROP.md, but it's not clear of how to override them.
d

Denis Shurygin

07/05/2018, 2:34 PM
So? The answer is no? I'm not sure that I right understand what is written in this paragraph.
Let me explain my question. This document has an example of usage following Objective-C methods.
[player moveTo:LEFT byMeters:17]
[player moveTo:UP byInches:42]
In Objective-c overriding can look as following:
-(void) moveTo:(int)direction byMeters:(double) distance {
...
}
But how do I override them in Kotlin Native?
a

AnaR

07/05/2018, 3:31 PM
I haven't done it yet. But, my guess it it would be how you'd do regular kotlin inheritance. I would try something like: override fun moveTo(direction:Int, byMeters:double)
s

svyatoslav.scherbina

07/06/2018, 8:18 AM
But, my guess it it would be how you’d do regular kotlin inheritance.
Exactly.
d

Denis Shurygin

07/06/2018, 9:07 AM
I wish so. But it's not working. This two methods have same set of parameters for Kotlin.
override fun moveTo(direction:Int, byMeters:double)
override fun moveTo(direction:Int, byInches:double)
They are equal from Kotlin piont of view. But not for Objective-C in case if you hawe two following methods:
-(void) moveTo:(int)direction byMeters:(double) distance
-(void) moveTo:(int)direction byInches:(double) distance
s

svyatoslav.scherbina

07/06/2018, 9:19 AM
They are equal from Kotlin piont of view.
They are not considered equal in this special case when overriding Objective-C methods. Have you tried to write such a code?
d

Denis Shurygin

07/06/2018, 11:48 AM
I tried to override following method of UIViewController (iOS UIKit):
func show(_ vc: UIViewController, sender: Any?)
Here is my implementation:
override fun show(vc: UIViewController, sender: Any?)  {
        super.show(vc, sender = sender)
    }
But I faced with 2 errors: 1 string: 'show' overrides nothing 2 string: Unresolved reference: show I use konan plugin version 0.7.1
s

svyatoslav.scherbina

07/06/2018, 1:20 PM
Yes, because this method is imported to Kotlin as
open external fun showViewController(vc: UIViewController, sender: Any?)
and thus should be called and overridden using this signature.
d

Denis Shurygin

07/06/2018, 3:16 PM
Thank you. Now it work.
Could you tell where did you get information about method signature?
s

svyatoslav.scherbina

07/23/2018, 1:56 PM
AppCode should show these signatures. Also you can get them using
klib
command-line util:
$ ./bin/klib contents ./klib/platform/ios_arm64/UIKit > log