Hey everyone. How are you guys exposing ViewState ...
# multiplatform
t
Hey everyone. How are you guys exposing ViewState in iOS? Normally, in pure android/kotlin I would so something to the likes of this:
Copy code
sealed class ViewState<T> {
object Loading<T> : ViewState()
class Success<T>(val data: T) : ViewState()
class Failure<T>(val error: Throwable): ViewState()
}
But since sealed classes don’t play nice in iOS, I’m wondering what approach you guys are taking?
m
I've just been still doing the sealed classes like I would if it was just an Android project. It's not as nice to use in Swift as in Kotlin, but is still pretty usable. There is a gradle plugin from someone that can convert sealed classes to Swift enums. I've not used it so I cannot give any feedback. https://github.com/icerockdev/moko-kswift
t
Thanks! I’ll give it another go. Saw this plugin too, but I couldn’t get this to work for me for some reason. Let me see if I can get it to work out of the box, searching the slack channel already gave me some insights too.
m
I use data class for the state and hold it in StateFlow I called this architecture MVVM SEED and here one of my SEED: https://github.com/Oztechan/CCC/blob/develop/client/src/commonMain/kotlin/com/oztechan/ccc/client/viewmodel/calculator/CalculatorSEED.kt