You wrote yourself that the asynchronic circuit is not going to be done at the time of execution, but only for a certain event, plus - the most likely execution of the block will be the same in the main flow, which means that it will never happen, because the flow will be fully occupied by the cycle. If you need to modify some variable in the aisynchronous block, you better do it in synchronize, but in your case it's not an answer. I'd like to know what exactly the purpose of your variable is? If you need to transfer the i value to the block, it's worth trying, for example, to find some kind of userData from Alamofire and to record the variable in it and in the block from there and deliver. Another option is to use an intermediate constant, for example:func getRegion2(){
let method = "region/"
var url = serviceUrl+method
var i = 0
while(i < 4){
i = i + 1
let iBlock = i
Alamofire.request(url).validate().responseJSON { response in
switch response.result {
case .success(let data):
let nextUrl = JSON(data)["next"].stringValue
url = nextUrl
print(iBlock)
print(nextUrl)
case .failure(let error):
print("Request failed with error: \(error)")
}
}
}
}