Does it possible to override Objective-C methods? ...
# kotlin-native
d
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
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.
Copy code
[player moveTo:LEFT byMeters:17]
[player moveTo:UP byInches:42]
In Objective-c overriding can look as following:
Copy code
-(void) moveTo:(int)direction byMeters:(double) distance {
...
}
But how do I override them in Kotlin Native?
a
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
But, my guess it it would be how you’d do regular kotlin inheritance.
Exactly.
d
I wish so. But it's not working. This two methods have same set of parameters for Kotlin.
Copy code
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:
Copy code
-(void) moveTo:(int)direction byMeters:(double) distance
-(void) moveTo:(int)direction byInches:(double) distance
s
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
I tried to override following method of UIViewController (iOS UIKit):
Copy code
func show(_ vc: UIViewController, sender: Any?)
Here is my implementation:
Copy code
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
Yes, because this method is imported to Kotlin as
Copy code
open external fun showViewController(vc: UIViewController, sender: Any?)
and thus should be called and overridden using this signature.
d
Thank you. Now it work.
Could you tell where did you get information about method signature?
s
AppCode should show these signatures. Also you can get them using
klib
command-line util:
Copy code
$ ./bin/klib contents ./klib/platform/ios_arm64/UIKit > log