Sto lavorando per modificare un codice Objective-C su Swift, e non riesco a capire per la vita di me come occuparmi di char array senza segno e operazioni bit a bit in questa specifica istanza di codice.Utilizzo di char array unsigned di stile C e operatori bit a bit in Swift
In particolare, sto lavorando sulla conversione il seguente codice Objective-C (che si occupa di CoreBluetooth) a 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);
ho provato quanto segue in Swift:
var advertisementBytes: CMutablePointer<CUnsignedChar>
self.proximityUUID.getUUIDBytes(advertisementBytes)
advertisementBytes[16] = (CUnsignedChar)(self.major >> 8)
I problemi che sto incontrando sono che getUUIDBytes in Swift sembra prendere solo un oggetto CMutablePointer<CUnsignedChar>
come argomento, piuttosto che un array di CUnsignedChars, quindi non ho idea di come eseguire le operazioni bitwise successive su AdvertisementBytes, come sembra deve essere un CH senza segno ar array per farlo.
Inoltre, CMutablePointer<CUnsignedChar[21]>
genera un errore che indica che gli array di lunghezza fissa non sono supportati in CMutablePointers in Swift.
Qualcuno può consigliare suggerimenti su possibili soluzioni o soluzioni? Grazie molto.
Potrebbe includere la 'Objective-C' anche le versioni? –