I have the following problem. I use this code below and I get the issue
"Variable 'characteristic' was never mutated; consider changing to 'let' constant"
for var characteristic:CBCharacteristic in service.characteristics ?? [] { print(str) _selectedPeripheral!.writeValue(str.dataUsingEncoding(NSUTF8StringEncoding)!, forCharacteristic: characteristic, type: CBCharacteristicWriteType.WithoutResponse) } When I change to "let", there's an Error:
'let' pattern cannot appear nested in an already immutable context
Why does it recommend me the change and afterwards mark it as an error?
You just need to remove var, making your code:
for characteristic in service.characteristics ?? [] { print(str) _selectedPeripheral!.writeValue(str.dataUsingEncoding(NSUTF8StringEncoding)!, forCharacteristic: characteristic, type: CBCharacteristicWriteType.WithoutResponse) } because characteristic is immutable by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With