I'm using KMP-NATIVECOROUTINES I want to read and ...
# multiplatform
i
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
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
Oh! it looks nice, I'll try, thanks!
👍🏻 1
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
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
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 🎉
👍🏻 1