如何快速获取枚举Int值
创建枚举
enum FriendActionType:Int {
case sendFriendRequest = 1, cancelFriendRequest, acceptFriendRequest, removeFromFriendList, deleteFriendRequest
}
不带散列的打印(完美的传递变量)
po "\(friendActionType)"
"deleteFriendRequest"
打印HashValue日志(打印错误的int值'-1188319181990702728'而不是'5')
po friendActionType.hashValue
-1188319181990702728
我要从枚举变量中获取Int
'5'值。
答案 0 :(得分:3)
使用friendActionType.rawValue
原始值示例
enum Planet: Int {
case mercury = 1, venus, earth, mars, jupiter, saturn, uranus, neptune
}
let earthsOrder = Planet.earth.rawValue
// earthsOrder is 3