Hello I am new to swift and would like to convert a byte array to several integers. I have written working code in Java but I am not quite sure how to take it to swift
byte[] codeData = Base64.decode(codeDataBase64, 0);
ByteArrayInputStream bais = new ByteArrayInputStream(codeData);
DataInputStream dis = new DataInputStream(bais);
byte version = dis.readByte();
if (version == 1) {
int anID = dis.readInt();
int anotherID = dis.readInt();
byte[] TK = new byte[512];
int readTK = dis.read(TK);
if (readTK == TK.length) {
Log.e("photoConnect success", "anID=" + anID + ", anotherID=" + anotherID + ", TK.length=" + TK.length);
Here is what I have in Swift thus far:
func base64ToByteArray(base64String: String) -> [UInt8]? {
if let nsdata = NSData(base64Encoded: base64String) {
var bytes = [UInt8](repeating: 0, count: nsdata.length)
nsdata.getBytes(&bytes, length: nsdata.length)
return bytes
}
return nil // Invalid input
}
This function takes it to an array of bytes but I am not sure what Swift class to use to mimic the behavior of DataInputStream in Java.