Bonjour, je cherche à traduire ce code objective c en swift:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
 
    if( !error)
    {
        [self modifMessage:@"Enregistrement des données"];
 
        NSData* data=characteristic.value ;
 
        const  char* bytes = (const  char*)data.bytes;
        NSMutableString* hex= [NSMutableString stringWithUTF8String:bytes];
 
        donnees=[donnees stringByAppendingString:hex];
 
        if ([hex rangeOfString:@"$"].location != NSNotFound) {
            [self finBluetooth];
        }
    }
}

Pour l'instant j'ai ça :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
       func peripheral(_peripheral: CBPeripheral!,
        didUpdateValueForCharacteristic characteristic: CBCharacteristic!,
         error: NSError!)
    {
        if( !error)
        {
            modifMessage("Enregistrement des données")
            var  data=characteristic.value
            var bytes   = data.bytes
           var hex = NSMutableString.stringWithUTF8String(bytes)
           var donnees = donnees.stringByAppendingString(hex)
            if ( hex.rangeOfString("$").location != NSNotFound) {
                finBluetooth()
            }
        }
    }
Sauf que ça plante parce que byte est considéré comme un COpaquePointer et stringWithUTF8String a besoin d'un cstring. Comment faire pour le transformer en cstring? J'ai essayer de caster dans tous les sens possibles , d'utiliser la fonction fromOpaque mais rien n'y fait.
HELP?!
Merci !