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

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -