Anton Afanasev
01/05/2022, 3:39 PMdata class Payload(val name: String)
sealed class Event {
class Inserted(val payload: Payload) : Event()
class Updated(val payload: Payload) : Event()
class UpdatedAll(val payloads: List<Payload>, val flag: Boolean) :
Event()
}
Paul Woitaschek
01/05/2022, 3:42 PMAnton Afanasev
01/05/2022, 3:43 PMPaul Woitaschek
01/05/2022, 3:45 PMPaul Woitaschek
01/05/2022, 3:49 PMPaul Weber
01/05/2022, 4:31 PMswitch event {
case is Inserted:
let inserted = event as! Inserted
// do something with inserted.payload
default:
break
}
Paul Weber
01/05/2022, 4:31 PMSam
01/05/2022, 5:05 PMswitch event {
case let inserted as Inserted:
// do something
default:
break
}
Paul Weber
01/05/2022, 5:06 PMAnton Afanasev
01/05/2022, 7:47 PMPaul Woitaschek
01/05/2022, 8:14 PMPaul Weber
01/05/2022, 8:19 PMwhen (SealedClass)
still compiles when you omit a case? It’s just a warning otherwise. So you’d still have to check KMM code to be sure it’s exhaustive.
I still liked it. Wouldn’t have thought of that myself. 👍🏼Paul Woitaschek
01/06/2022, 5:56 AM