david.bilik
09/19/2022, 9:14 AMsealed class State<out T> {
object Loading : State<Nothing>()
data class Error(val error: Throwable) : State<Nothing>()
data class Loaded<out T>(val data: T) : State<T>()
}
in my shared kotlin code, then I have a viewmodel emitting these different states during async call. Now I want to check in my iOS swift code for a type of a State so I can either show loading/loaded/error views but I have a hard time figuring out how to do this type check. The only way where my type check succeeds is for the State.Loaded
, but for Error or Loading it shows a warning
Cast from 'State<Character>' to unrelated type 'StateLoading' always fails
I suppose it’s because the Loading and Error does not have the type parameter, but how to do this properly?Nicolas Patin
09/19/2022, 9:39 AMswitch state {
case _ as State.Loading:
// show loading
break
case let state as State.Error:
// show error
let error = state.error
case let state as State.Loaded:
// show loaded
let data = state.data
default:
fatalError("\(state) is not handled yet.")
}
david.bilik
09/19/2022, 9:47 AMState.Loaded
is not recognized and when I open the generated code for eg. loading state it looks like this
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("StateLoading")))
@interface SharedStateLoading : SharedState<SharedKotlinNothing *>
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)loading __attribute__((swift_name("init()")));
@property (class, readonly, getter=shared) SharedStateLoading *shared __attribute__((swift_name("shared")));
@end;
okarm
09/19/2022, 9:55 AMSeb Jachec
09/19/2022, 9:57 AMNicolas Patin
09/19/2022, 10:01 AMdavid.bilik
09/19/2022, 10:02 AM