https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
l

Lena Brusilovski

03/22/2021, 12:20 PM
is there a way to do expect/actual for enums?
d

Dominaezzz

03/22/2021, 1:00 PM
Yes, e are you experiencing any issues?
l

Lena Brusilovski

03/22/2021, 1:01 PM
I dont know how to do it. I have ios variables that are longs and ios variables that are ints, i want to unify them somehow. How do I define it?
d

Dominaezzz

03/22/2021, 1:11 PM
Expect the enum name and entry names, then you do an actual for the implementation. I'd type up an example if I was at my computer.
l

Lena Brusilovski

03/22/2021, 1:11 PM
could you do that, once you do get to your computer ?
d

Dominaezzz

03/22/2021, 1:12 PM
Sure
l

Lena Brusilovski

03/22/2021, 1:12 PM
thx
c

CLOVIS

03/22/2021, 1:54 PM
Maybe something like:
Copy code
// Common
enum class MyEnum {
  V1,
  V2
}
expect MyEnum.value: Number
Copy code
// iOS
actual MyEnum.value: Int
  get = when (this) {
    V1 -> 1
    V2 -> 2
  }
l

Lena Brusilovski

03/22/2021, 7:00 PM
thx, its working
d

Dominaezzz

03/22/2021, 9:23 PM
Copy code
expect enum class MyEnum {
    V1, V2;
}

actual enum class MyEnum(val value: Int) {
    V1(0), V2(1);
}

actual enum class MyEnum(val value: Long) {
    V1(0), V2(1);
}
208 Views