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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -