How to Synchronize iOS class object (Swift / iOS 9)
<p>I have a class method, This method will take some time to get data from an http request.</p>

<p>Related part of the method:</p>

<pre><code>do{
    request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(params, options: NSJSONWritingOptions())
} catch {
    print("Cound not serilize")
}
let task = session.dataTaskWithRequest(request) {
    data, response, error in
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as? NSDictionary
self.result = json! as? [String : AnyObject]
print(self.result)
</code></pre>

<p>It will print correct result from JSON, but in other side the object instance <code>authGuestAPI</code> will not:</p>

<pre><code>let authGuestAPI = API(url: apiUrl, params: params, method: "POST")
authGuestAPI.run()
print("RESULT: \(authGuestAPI.result)")
</code></pre>

<p>It will print "RESULT: nil"</p>

<p>but If I put <code>NSThread.sleepForTimeInterval(2)</code> before <code>print("RESULT: \(authGuestAPI.result)")</code> It will print correct json data.</p>