How to do multi switch cases like Swift in Kotlin ...
# announcements
z
How to do multi switch cases like Swift in Kotlin using when?
Copy code
func getMode() -> Mode {
        var mode: Mode = .live
        switch (gdIsLocked, gdIsCurrent, matchIsLocked, matchIsCurrent) {
        case (0,1,0,1):
            mode = .manage
        case (1,1,1,1):
            mode = .live
        case (1,1,1,0):
            mode = .substitution
        case (1,2,1,2):
            mode = .points
        case (0,0,0,0):
            mode = .upcoming
        default:
            mode = .upcoming
        }
        return mode
    }

    enum Mode {
        case manage
        case substitution
        case live
        case points
        case upcoming
    }
❤️ 1
Has 4 values and then checked in the case is it possible to do in Kotlin?
Copy code
switch (gdIsLocked, gdIsCurrent, matchIsLocked, matchIsCurrent)
n
I think you'd need to create a dataclass holding 4 booleans
e
getMode.kt
☝️ Unless I understood it wrong, it should be possible using lists
z
Need to test this @edrd
n
Yeah a list would work fine as well