I'm using KMP-NATIVECOROUTINES
I want to read and modify an state from SwiftUI, but the generated code is this one:
Copy code
@ObjCName(name = "navigationtest")
@ShouldRefineInSwift
public var HomeViewModel.navigationtestValue: Boolean
get() = navigationtest.value
set(`value`) {
navigationtest.value = value
}
how can I refine that variable in swift?
r
Rick Clephas
01/23/2024, 12:38 PM
ShouldRefineInSwift
declarations are prefixed with
__
in Swift.
This prevents them from showing in Xcode autocomplete.
With a Swift extension for
HomeViewModel
(or a subclass):
Copy code
extension HomeViewModel {
var navigationtest: Bool {
get { __navigationtest }
set { __navigationtest = newValue }
}
}
you can access the hidden property and refine it however you like.
Obviously you would want a different implementation for the property as itβs currently not doing anything.
i
Ivan Carracedo Asensio
01/23/2024, 12:40 PM
Oh! it looks nice, I'll try, thanks!
ππ» 1
Ivan Carracedo Asensio
01/24/2024, 8:39 AM
It worked, thanks! Anyways, what I'm trying to do is exactly what you wrote, a double way mutable variable, is there any way or annotation to create a doubleway mutablestateflow( for example) boolean? or strings? like for example to use in a field of SwiftUI, it has to be double way for SwiftUi to update the variable and the UI? If this is not possible, I guess I'll just do the extension for any variable I need?
Thank you!
r
Rick Clephas
01/24/2024, 10:02 AM
When you are using KMP-NativeCoroutines you can use the
@NativeCoroutinesState
annotation. This will generate a mutable property for the MutableStateFlow.
In that case there is no need to refine the property in Swift.
β 1
i
Ivan Carracedo Asensio
01/24/2024, 11:55 AM
It's true... I don't know which kind of tests I did, but I wasn't seeing the setter(I've been nonstop with KMP since December, I don't even remember my name xD)
Appreciate your answers! And congrats for those amazing libraries π