Skip to content

Instantly share code, notes, and snippets.

@timothy1ee
Last active January 2, 2016 13:09
Show Gist options
  • Save timothy1ee/8308396 to your computer and use it in GitHub Desktop.
Save timothy1ee/8308396 to your computer and use it in GitHub Desktop.
Objective C Rotten Tomatoes snippet
NSString *url = @"http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=dagqdghwaq3e3mxyrp7kmmj5&limit=20&country=us";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
id object = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", object);
}];
@chug2k
Copy link

chug2k commented Aug 25, 2015

Translated to Swift:

        let url = "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=dagqdghwaq3e3mxyrp7kmmj5&limit=20&country=us"
        let request = NSURLRequest(URL: NSURL(string: url)!)

        NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) -> Void in
            let responseDict: NSDictionary = NSJSONSerialization.JSONObjectWithData(data,options: NSJSONReadingOptions.MutableContainers, error:nil) as! NSDictionary

            println(responseDict)

        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment