Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift equivalent of Enum.ordinal() in Java

Tags:

java

enums

swift

I was wondering if there is a Swift equivalent of Java's Enum.ordinal() method.

like image 837
Juventus Avatar asked Aug 31 '25 04:08

Juventus


1 Answers

You can use rawValue to access the ordinal value of an enum marked with Int.

enum SomeEnum: Int {
    case first
    case second
    case third
    case fourth
}

print(SomeEnum.third.rawValue) //2
like image 96
Tamás Sengel Avatar answered Sep 02 '25 17:09

Tamás Sengel