swift2 - "Variable 'xxx' was never mutated; consider changing to 'let' constant" ERROR -


i have following problem. use code below , issue

"variable 'characteristic' never mutated; consider changing 'let' constant"

for var characteristic:cbcharacteristic in service.characteristics ?? [] {     print(str)     _selectedperipheral!.writevalue(str.datausingencoding(nsutf8stringencoding)!, forcharacteristic: characteristic, type: cbcharacteristicwritetype.withoutresponse) } 

when change "let", there's error:

'let' pattern cannot appear nested in immutable context

why recommend me change , afterwards mark error?

you need remove var, making code:

for characteristic in service.characteristics ?? [] {     print(str)     _selectedperipheral!.writevalue(str.datausingencoding(nsutf8stringencoding)!, forcharacteristic: characteristic, type: cbcharacteristicwritetype.withoutresponse) } 

because characteristic immutable default.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -