https://kotlinlang.org logo
a

ade

02/25/2022, 9:27 AM
I have a custom result-like class that has served me well in kotlin/android;
Copy code
sealed class Resolved<out T> {
    data class Success<out T>(val data: T) : Resolved<T>()
    data class Error(val exception: Exception) : Resolved<Nothing>()
But in case of Error, how can I extract the exception on the iOS side? If Resolved.Error has a type parameter (Error<T>) i can do in swift:
if
*let* val = response *as*? ResolvedError { ...
But when it doesnt and is typed as Resolved<Nothing> I cannot. Or at least I don't know how. Any tips?
actually this can trivially solved on the kt side by doing e.g.
Copy code
fun <T> Resolved<T>.errorOrNull() = (this as? Resolved.Error)?.exception
and in swift
if
*let* val = response?.errorOrNull() {
print("Found an exception \(val)")
}
3 Views