Swift: Making Network Request Using NSURLConnection

From Hawk Wiki
Revision as of 04:03, 23 March 2015 by Hall (Talk | contribs) (Created page with "<pre class="brush:swift"> var clientId = "Put your client id here" var url = NSURL(string: "https://api.instagram.com/v1/media/popular?client_id=\(clientId)")! var request =...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
var clientId = "Put your client id here"
 
var url = NSURL(string: "https://api.instagram.com/v1/media/popular?client_id=\(clientId)")!
var request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
    var responseDictionary = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSDictionary
    self.photos = responseDictionary["data"] as NSArray
    self.tableView.reloadData()
    
    println("response: \(self.photos)")
}