There is a code:
func loadShots(shotsUrl: String, completion: (([Shot]) -> Void)!) { let urlString = "https://api.dribbble.com/v1/shots?access_token=" + accessToken let session = NSURLSession.sharedSession() let shotUrl = NSURL(string: urlString) let task = session.dataTaskWithURL(shotUrl!) { (data, response, error) -> Void in if error != nil { print(error?.localizedDescription) } else { var shots = [Shot]() var error : NSError? var shotsData = try? NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers ) as! NSArray for shot in shotsData! { let shot = Shot(data: shot as! NSDictionary) shots.append(shot) } let prioriry = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(prioriry, 0)) { dispatch_async(dispatch_get_main_queue()) { completion(shots) } } } } task.resume() } Why shots after build shows 0 elements? What did I do wrong?
shotjust in case you have two of them there. - Max Mikheyenko 1:01 pmShot(data:)exactly taking a Dictionary? Something seems to me that NSData would make more sense there - Max Mikheyenko