Reputation: 5223
How to get enum Int value in swift
Create Enum
enum FriendActionType:Int {
case sendFriendRequest = 1, cancelFriendRequest, acceptFriendRequest, removeFromFriendList, deleteFriendRequest
}
Print without hash (Perfect pass variable)
po "\(friendActionType)"
"deleteFriendRequest"
Print HashValue Log (Print wrong int value '-1188319181990702728' instead of '5')
po friendActionType.hashValue
-1188319181990702728
I want Int
'5' value from enum variable.
Upvotes: 1
Views: 292
Reputation: 143
Use friendActionType.rawValue
example of rawvalue
enum Planet: Int {
case mercury = 1, venus, earth, mars, jupiter, saturn, uranus, neptune
}
let earthsOrder = Planet.earth.rawValue
// earthsOrder is 3
Upvotes: 4