How to call a selector from kotlin for iOS


I’m trying out the konan iOS sample app, and hoping I can create a view and set its attributes directly from kotlin, without going through Storyboards.

Another thing I’m not sure how to do is how to set an action for a UIButton without going through the Storyboard.

I have the button object button, and trying to set its target selector by calling:

button.addTarget(this, action=::buttonPressed, forControlEvents=UIControlEventTouchDown)

The action selector gives this error message:

Type mismatch: inferred type is KFunction0 but COpaquePointer? /* = CPointer? */ was expected

::buttonPressed was the closest I got to a selector in kotlin, could you advice on how to achieve this?

Not sure who the correct people are; maybe @yole or @elizarov?


Maybe you can call sel_registerName("buttonPressed")? According to


Ok, sounds like it’s worth a shot. I’ll need to wait until I’ve resolved How to call non-UIKit functions for iOS before I can try it, since calling that function gives me an unresolved reference compile error.