var arrayData: [String] = []
let bodyData = \"parameter=test\"
let URL: NSURL = NSURL(string: \"Link to php file\")
let request:NSMutableURLRequest = NSMutableURLReque
sendAsynchronousRequest
is, as the name suggests, asynchronous. So your final println
runs before the request is complete. After the completion handler runs, the new data will be available for all readers (in or outside this handler).
sendAsynchronousRequest
requires a callback passed as argument, which is executed once the asynchronous request has been completed. That's out of the linear flow in your code.
This is what happens:
sendAsynchronousRequest
println
line is executed next (last line in your code)self.arrayData
If you want to use the updated value, you have to change the logic a little bit. You can call another closure or a class method (meaning an instance method, not a static one) to post process that variable once it has been set.