Any idea how I could work around the fact you can’...
# ios
r
Any idea how I could work around the fact you can’t override
UIView.draw
?
It’s exposed to Kotlin as an
@ObjCMethod external
extension function of
UIView
So obviously this does not work
l
@ribesg remove
external
and
@ObjCMethod
, it should work after that. That's a tooling issue, reporting it would make sense.
r
Oh, didn't even check if it was an IDE issue and actually compiled
l
You confirm it now works?
r
It doesn’t seem to work, no. But as the IDE doesn’t help I’m not sure what I write is correct anyway. It says it overrides nothing, as I expected
The function I want to override:
@kotlinx.cinterop.ObjCMethod public external fun platform.UIKit.UIView.drawRect(rect: kotlinx.cinterop.CValue<platform.CoreGraphics.CGRect>): kotlin.Unit { /* compiled code */ }
@louiscad what makes you think it should work? Did you manage to make it work in some case already? https://kotlinlang.org/docs/reference/native/objc_interop.html#category-members
l
Oh, that's a category member! I don't recall for which function I made it work, but it seems that is a current limitation of Kotlin/Native. @kpgalligan do you know why there is this limiation, and if there's a workaround?
r
Well.
While the use of drawRect is common, it’s a practice that has been discouraged since at least 2002/2003
Apparently you should ‘now’ (and for the last 18 years) use drawLayer, which can be overridden apparently. But yeah the question’s still there, will we be able to override these at some point?