Your example does not make sense @newacct. The variable x actually changes outside the block. Swift is smart enough to find out if you are changing a variable inside or outside of a closure.
As the document says:
As an optimization, Swift can instead capture and save a copy of the value if that value is not mutated by the closure or outside.
Regarding the post by @Eonil question, in the first snippet, you have a strong reference to Optional<AAA> in the close. However, when you set a1 to nil, what you are actually doing is removing the value of type AAA, which is wrapped inside optional.
When you call closure a2 , you return the same optional, with no value inside, which exactly means nil . So having a strong link means your close has the same meaning as a1 . This does not mean that this optional parameter cannot be set to nil.
In the second code snippet, you wrote a1 to the capture list. This means that you copy a1 and the value of a1 inside the closure has nothing to do with the value of a1 outside the closure. Therefore, even if you set a1 to zero, it does not affect what you get from closing.
My English is not very good, and I hope that I expressed my opinion clearly. Or you can read this article , I think this will help you a lot.
source share