-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS nullable value from CStateFlow #181
Comments
Hey @kramlex, I tried to use your solution, but could not get it working. I added a debug output, but it only prints func stateNullable<T, R>(
_ flowKey: KeyPath<Self, CStateFlow<T>>,
equals: @escaping (T?, T?) -> Bool,
mapper: @escaping (T?) -> R?
) -> R? {
let stateFlow: CStateFlow<T> = self[keyPath: flowKey]
var lastValue: T? = stateFlow.value
var disposable: DisposableHandle?
disposable = stateFlow.subscribe(onCollect: { value in
print(value)
if !equals(lastValue, value) {
lastValue = value
self.objectWillChange.send()
disposable?.dispose()
}
})
return mapper(stateFlow.value)
} My code in the KMM module looks like this: private var _availableItems = MutableStateFlow<List<Item>?>(null)
val availableItems = _availableItems.cStateFlow() Inside my SwiftUI view, I am calling it like this: vehicles: viewModel.stateNullable(\.availableItems, equals: { $0 === $1 }, mapper: { $0 as! [Item]? }), The normal/predefined states work just fine. Do you have any hint what I am missing? Edit: after switching to a non-nullable list, I got the similar effect that the list value is not updated and stays empty. So from m experience, there seems to be a problem with lists in general. Edit 2: I could work around this limitation by using the state pattern in your example. As the state is always non-nullable, the code from above is not even need. Nevertheless, it would still be nice if nullable data types would be supported. |
Hi, @ln-12. I analyzed your problem and couldn't reproduce it. The proposed solution works correctly. |
Thanks @kramlex, I found another approach which is working fine for me. |
will be released in 0.15.0 |
mokoMvvmFramework does not allow to get a iOS nullable value from CStateFlow, , it is necessary to add
at the moment, force unwrap is being used there
The text was updated successfully, but these errors were encountered: