I've been having trouble using sealed classes on t...
# touchlab-tools
s
I've been having trouble using sealed classes on the iOS/Swift side of my app. Basically, I have a sealed class with a generic type parameter like so:
Copy code
sealed class UiState<out T> {
    data object Loading : UiState<Nothing>()
    data class Success<T>(val data: T) : UiState<T>()
    data class Error(val message: String) : UiState<Nothing>()
}
and I have a
viewModel
I have in Swift using the observable protocol:
Copy code
@MainActor
class ContentViewModel: ObservableObject {
    let profile = MyProfile()
    @Published
    private(set) var currentState: UiState<RawProfile> = ...
    
    
    func observeProfile() async {
        for await state in self.profile.profileData {
            self.currentState = state
        }
    }
}
I want to initialize
currentState
with
UiState.Loading
But I can't seem to figure out the syntax to fill in the
...
Any help would be very much appreciated!
t
Hi, this would be better asked in #C3PQML5NU. In any case, try
UiStateLoading.shared
. If your Kotlin framework is called
shared
, SKIE has to rename the
.shared
to
.shared_
so it might be
UiStateLoading.shared_
instead.
👍 1
s
Thanks -
UiStateLoading.shared_
doesn't seem to exist, and using
UiStateLoading.shared
gives the following error:
Cannot convert value of type 'UiState<KotlinNothing>' to expected argument type 'UiState<RawProfile>'
t
I see, yeah that makes sense, because Swift doesn't have a type that'd work the same way
Nothing
does in Kotlin, where
Nothing
conforms to any other type, so you can't really assign it this way