https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Mgj

07/09/2020, 1:18 PM
For iOS, anyone know a resource for how to define CPointers? Im trying to do something like this:
Copy code
val view: UITextField
view.addTarget(target = view, action = ::onTextChanged, forControlEvents = UIControlEventEditingChanged)
But its not allowed because Required: COpaguePointer? Found: KFunction0 Apparently theres an
toCPointer()
function? I cant seem to import it, so im unsure how its to be used
k

Kris Wong

07/09/2020, 1:36 PM
Copy code
addTarget(
                target = this@FeatureDataSource,
                action = sel_registerName("onFeatureToggled:"),
                forControlEvents = UIControlEventValueChanged
            )
m

Mgj

07/09/2020, 1:38 PM
Thank you. I actually saw the
sel_registerName
but im not sure how to do closures with it. For example i'd like to pass my own extra argument to it, is that possible?
k

Kris Wong

07/09/2020, 1:39 PM
no
iOS doesn't support that
IIRC you can take 0 or 1 argument, and if you take 1, it will be the control itself
m

Mgj

07/09/2020, 1:40 PM
That makes sense. But the
action
argument seems to accept a pointer and if thats true i should be able to include any closures i want if im able to pass an arbitrary function pointer
ofc i cannot do that if
sel_registerName
is the only way to do it 😕
k

Kris Wong

07/09/2020, 1:43 PM
it must be a
@ObjCAction fun
or it will crash at runtime
m

Mgj

07/09/2020, 1:43 PM
I see
k

Kris Wong

07/09/2020, 1:44 PM
in my case i created a map of control to data
m

Mgj

07/09/2020, 1:45 PM
My real issue is actually that i want to bind an UITextField to a MutableStateFlow<String> (two-way, input to TextField should change value of StateFlow, and vice versa). It seems like swift has very limited support for StateFlow e.g. i dont seem to be able to use
onEach
in swift so i figured i'd try to do the binding in kotlin
Guess i could technically do the StateFlow->TextField subscription in kotlin and the TextField->StateFlow in swift but that seems like a very messy solution
8 Views