-
I want to ask for a reason to define Value as Is it intended? In my project i need to use Currently I forced to use it with custom wrapper (like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Thanks for the question! This was already discussed a while ago. But it's good to repeat it here as well. Here is the copy of the original answer. This is by design, due to how generics are exported to Swift. If we define it as For the same reason they both are classes, and not interfaces. Because generics for an interface cannot be exported to Swift. You can workaround nullable types by using something like |
Beta Was this translation helpful? Give feedback.
-
Maybe its a good idea to add helper functions/classes into a separate module like the compose extensions for different use cases. In my case I'd like to use Kotlin flows, however their interop with swift is bad. Therefore I like your design decision with an own state holder (Value::class).
Now use the mutableFlows in your components and expose them via .asValue(scope). The Optional data class allows nullable values and is hidden behind the subscribeAsState extension when using in compose.
|
Beta Was this translation helpful? Give feedback.
Thanks for the question! This was already discussed a while ago. But it's good to repeat it here as well. Here is the copy of the original answer.
This is by design, due to how generics are exported to Swift. If we define it as
Value<T>
, then a non-null type (e.g.Value<String>
) will be still nullable in Swift.For the same reason they both are classes, and not interfaces. Because generics for an interface cannot be exported to Swift.
You can workaround nullable types by using something like
data class Optional<T : Any>(val value: T?)
.