lambda - Swift closures change captured variable -


i'm using closure

{ [capturedvar] othervar in     // code here } 

when try change capturedvar, error appears, saying it's constant , cannot changed. there way change captured variable inside closure (i need original changed to, copying not option)?

as of swift 2, captured variables constants , behavior cannot changed.

you can change variable within closure way (it's sort of trick):

{   [capturedconst] othervar in     var capturedvar = capturedconst     // code here } 

you have stated you'd change original variable, too:

in case suggest check inout parameter definition or, eventually, return new changed variable closure.


Comments