I am working on changing Objective-C code to Swift, and I cannot figure out how much I should care about unsigned char arrays and bitwise operations in this particular code instance.
In particular, I am working on converting the following Objective-C code (which deals with CoreBluetooth) to Swift:
unsigned char advertisementBytes[21] = {0}; [self.proximityUUID getUUIDBytes:(unsigned char *)&advertisementBytes]; advertisementBytes[16] = (unsigned char)(self.major >> 8); advertisementBytes[17] = (unsigned char)(self.major & 255);
I tried the following in Swift:
var advertisementBytes: CMutablePointer<CUnsignedChar> self.proximityUUID.getUUIDBytes(advertisementBytes) advertisementBytes[16] = (CUnsignedChar)(self.major >> 8)
The problems I'm encountering is that getUUIDBytes in Swift apparently only accepts a CMutablePointer<CUnsignedChar> object as an argument, not a CUnsignedChars array, so I have no idea how to perform later bitwise operations on advertBytes, like it seems there must be an unsignedChar array for this.
In addition, CMutablePointer<CUnsignedChar[21]> displays a message stating that fixed-length arrays are not supported in CMutablePointers in Swift.
Can anyone consult with potential problems or solutions? Many thanks.
objective-c swift
Will jack
source share