You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
Overriding most methods appears to work in KotlinNative, but for whatever reason, the layout methods on UIView appear to give a compile error when you try to override them.
Specifically, they give errors like 'layoutSubviews' overrides nothing.
@ExportObjCClass
class MyView : UIView {
constructor(frame: CValue<CGRect>) : super(frame);
override fun layoutSubviews() // Compile error here: 'layoutSubviews' overrides nothing
{
println("this function was called to layout subviews!!!")
}
}
Checking the objc.kt file from an older version of KotlinNative suggests that maybe the problem is that layoutSubviews is defined in the interop as an extension method rather than a method on the base class?
How / What is the best practice for overriding this method on UIView?
The text was updated successfully, but these errors were encountered:
jimgoog
changed the title
Failure to override some methods when UIView is the parent/base class
Failure to override some methods when UIView is the super class
Nov 14, 2017
maybe the problem is that layoutSubviews is defined in the interop as an extension method rather than a method on the base class?
Yes, this seems to be the case. layoutSubviews is declared as category method in Objective-C headers, and category methods are currently represented as Kotlin extension methods.
Extension methods can't be overridden in Kotlin. However, as a workaround, you can declare layoutSubviews Kotlin method without override keyword, and add @ObjCAction annotation to make it visible through Objective-C virtual dispatch:
class MyView : UIView {
@ObjCAction fun layoutSubviews() {
...
}
}
(Note that @ObjCAction is applicable to methods with very strict constraints on their signatures, namely methods that can be used as actions in target-action pattern. That's why adding @ObjCAction is just a workaround).
Overriding most methods appears to work in KotlinNative, but for whatever reason, the layout methods on
UIView
appear to give a compile error when you try to override them.Specifically, they give errors like
'layoutSubviews' overrides nothing
.Checking the objc.kt file from an older version of KotlinNative suggests that maybe the problem is that layoutSubviews is defined in the interop as an extension method rather than a method on the base class?
How / What is the best practice for overriding this method on UIView?
The text was updated successfully, but these errors were encountered: