有什麼辦法從NSData對象創建ENUM嗎? 我從藍牙設備收到一個NSData,讓它更具可讀性,我正在考慮使用ENUM。從NSData創建ENUM
我現在代碼:
let data = NSData(bytes: [0x00, 0x12] as [UInt8], length: 2)
let initData = NSData(bytes: [0xa2,0x12] as [UInt8], length: 2)
let openedData = NSData(bytes: [0xa1,0x12] as [UInt8], length: 2)
let alreadyOpenedData = NSData(bytes: [0xa1,0x13] as [UInt8], length: 2)
let finishedData = NSData(bytes: [0xa3,0x12] as [UInt8], length: 2)
switch data{
case openedData:
print("opened")
break
case alreadyOpenedData:
print("alreadyOpened")
break
case initData:
print("ini")
break
case finishedData:
print("finished")
default:
print("error")
}
你想打的NSData的枚舉?你不能,NSData不能轉換成任何文字或符合RawRepresentable協議。 – JAL