Joaquim Ley
12/29/2020, 4:33 PMsealed class Result<T> {
Success(val data: T): Result()
Error(val message: T): Result()
}
How would you switch case with a swift optional + handle both success and error cases?Javier
12/29/2020, 6:07 PMSam
12/29/2020, 11:05 PMswitch
over a sealed class you can use:
switch result{
case let success as ResultSuccess:
print("success")
case let failure as ResultFailure:
print("failure")
default:
break //Swift will require an exhaustive switch
}
I think but am not positive that you could include type parameters on those let
lines.Joaquim Ley
12/30/2020, 12:57 PMJoaquim Ley
12/30/2020, 4:01 PMSam
12/30/2020, 4:30 PM@interface MyModule_modulePrefixLoading : MyModule_modulePrefixViewState
If that is not there, then maybe your Kotlin definition is off and the sealed classes aren’t inheriting from a common base.Joaquim Ley
12/30/2020, 5:30 PMopen class LoginState : KotlinBase {
}
extension LoginState {
public class Error : LoginState {
(other states here)
My issue is I can’t set a variable with another state , let’s say I declare said var in swift:
@Published var state: LoginState
now I can’t set it as (for instance) loading
state = LoginState.Loading
Joaquim Ley
12/30/2020, 5:31 PM