How do i convert HexString To ByteArray in Swift 3
问题 I'm was trying to convert hexString to Array of Bytes([UInt8]) I searched everywhere but couldn't find a solution. Below is my swift 2 code func stringToBytes(_ string: String) -> [UInt8]? { let chars = Array(string) let length = chars.count if length & 1 != 0 { return nil } var bytes = [UInt8]() bytes.reserveCapacity(length/2) for var i = 0; i < length; i += 2 { if let a = find(hexChars, chars[i]), let b = find(hexChars, chars[i+1]) { bytes.append(UInt8(a << 4) + UInt8(b)) } else { return