You can explicitly commit the value of i using the capture list [i] in the close, then you do not need to copy it to a separate variable. Example:
let c = 5 for var i=0; i<c; i++ { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { [i] in
Output:
i 0 c 5
i 1 c 5
i 2 c 5
i 3 c 5
i 4 c 5
source share