Difference between revisions of "Swift code snippets"

From Hawk Wiki
Jump to: navigation, search
(Created page with "==Making Network Request== <pre> var clientId = "Put your client id here" var url = NSURL(string: "https://api.instagram.com/v1/media/popular?client_id=\(clientId)")! var reque...")
(No difference)

Revision as of 03:27, 6 February 2015

Making Network Request

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)")
}