I have a simple Resource Class defined in my shared module - I usually use it as data types for flows returned from my repositories:
sealed class Resource<out T : Any>(open val data: T? = null) {
data class Success<out T : Any>(override val data: T) : Resource<T>()
class Failed<out T : Any>(val msg: String, val cause: Throwable? = null, data: T? = null) : Resource<T>(data)
class Loading<out T : Any>(data: T? = null) : Resource<T>(data)
}
I also have a mapper function with allows mapping the data type to something else:
fun <T : Any, R : Any> Resource<T>.map(mapper: (T) -> R): Resource<R> = ...
This works great on the Kotlin end of things. But I’m loosing all generic information on the Swift end in the mapper function. It seems to just be converted to
(Any) -> Any
which means I need to constantly cast to get what I want which makes the code look really ugly.
I read through the official docs and understand, that this is expected. But is there a better way to handle generic and/or generic resources to make them more Swift compatible?