Is there a way to save the current value of a varible for later usage in a block?
For example, for this Playground code:
import UIKit
import XCPlayground
Since you're referencing i
through a captured self
, you will get whatever the value is at dispatch time. If you want to capture the value as it is at the beginning of the function, you'll need to get a local copy before changing it.
let x = self.i
dispatch_after(dispatchTime, dispatch_get_main_queue(), {
self.test(x)
})