【发布时间】:2019-02-04 04:54:38
【问题描述】:
使用 Xcode 9.4.1 和 Swift 4.1
如果枚举了 Int 类型的多个案例,我如何通过其 rawValue 打印案例名称?
public enum TestEnum : UInt16{
case ONE = 0x6E71
case TWO = 0x0002
case THREE = 0x0000
}
我正在通过 rawValue 访问枚举:
print("\nCommand Type = 0x" + String(format:"%02X", someObject.getTestEnum.rawValue))
/*this prints: Command Type = 0x6E71
if the given Integer value from someObject.TestEnum is 28273*/
现在我还想在 HEX 值之后打印“ONE”。
我知道这个问题:How to get the name of enumeration value in Swift? 但这是不同的,因为我想通过案例原始值而不是枚举值本身来确定案例名称。
期望的输出:
命令类型 = 0x6E71, ONE
【问题讨论】:
-
请在您的问题中添加/打印您想要的确切输出。