Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App Downloading Data with NSURLSession NSURLSession Basics

What am I doing wrong?????!!

NSURL*url=[[NSURL alloc]initWithString:@"http://teamtreehouse.com"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];

  NSURLSessionDownloadTask*task=[session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error){
        NSLog(@"Response:%@",response);
    }];

    [task resume];
}

this is part of the challenge

2 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

The property NSURLSessionDownloadTask *task; is already made so all you need to do is:

task=[session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error){
        NSLog(@"Response: %@",response);
    }];

    [task resume];
Misha Shaposhnikov
Misha Shaposhnikov
8,718 Points

The Treehouse Code Challenge engine is really picky about these kinds of things. Add a space between the colon and the % symbol in the NSLog. If all else fails, here is what worked for me:

/* Add task 1 code here */
NSURL *url = [[NSURL alloc] initWithString : @"http://teamtreehouse.com"];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];

/* Add task 2 code below */
NSURLSessionDownloadTask *task;

task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location,NSURLResponse *response, NSError *error){
NSLog(@"Response: %@", response);
}];

[task resume];

Amit Bijlani please have a look at this. =)