I am trying to convert UUIDv4 into byte array for CloudSQL backend storage. I have removed the dashes, converted each char into its 4 bit hex binary string and have stitched them all back together into a 16 byte array.
But I am now trying to send this to a Node.js server and Alamofire 4 needs it as a string to send as a parameter. But I cannot convert "010001010" binary strings into characters. I can create Data or NSData from the byte array but cannot make the final conversion to String. Get the following error with the below code:
fatal error: unexpectedly found nil while unwrapping an Optional value
let byteArray:[UInt8] = [0xa2, 0x00]
let dataByteArray = Data(byteArray)
let data = NSData(data: dataByteArray)
Error here --> let resultNSString = NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue)!
let resultString = resultNSString as String
//let uuidString = String(data: data, encoding: .utf8)
print(resultString)
return resultString
}