user3731622
user3731622

Reputation: 5095

Swift can closures really modify constants?

In the subsection Capturing Values of the section Closures, Apple's book The Swift Programming Language says

The closure can then refer to and modify the values of those constants and variables from within its body, even if the original scope that defined the constants and variables no longer exists.

Upvotes: 0

Views: 49

Answers (1)

David Berry
David Berry

Reputation: 41226

It should be written as "refer to constants and refer to and modify variables" Try the following in a playground:

let x = 1

println(x)

{ x = x + 1 }()

println(x)

Upvotes: 1

Related Questions