Archive for August, 2017

Parsing Hex Strings in Swift

Saturday, August 12th, 2017

I want to turn the string “0x02 0x03 0x04” into an array of bytes ([UInt8]). Seems simple enough right? let hex = “0x02 0x03 0x04″ let components = hex.components(separatedBy: ” “) let array = { UInt8($0) } But the UInt8 constructor that takes a string doesn’t understand the “0x” prefix to indicate hex strings. […]