mardi 2 décembre 2014

How to send an NSNotification for when JSON is downloading

I'm downloading JSON to my app and am not sure how to tell the app that the JSON is done downloading. I'm thinking the best way is with NSNotificationCenter but I'm exactly sure how to do that.


Here's my code:



func downloadJSON(){

let p = NSURLRequest(URL: NSURL(string: "http://ift.tt/1BbDSqs")!)

let sharedSession = NSURLSession.sharedSession()

let dwn = sharedSession.dataTaskWithRequest(p, completionHandler: { (data : NSData!,re : NSURLResponse!, error: NSError!) -> Void in

if error == nil {

let js : AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as NSArray

self.quotes = js as NSArray

}



})

dwn.resume()

}


Any ideas? Thanks :)




Aucun commentaire:

Enregistrer un commentaire