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
Kirill Pahnev
30 PointsPhoto Bomber app not working?
So I'm trying to follow the tutorial but there's a problem. When I create this code it works as expected and log shows that I'm getting what I want.
NSURLSession *session = [NSURLSession sharedSession];
NSURL *url = [[NSURL alloc] initWithString:@"http://myurl.com/data.json"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSData *data = [[NSData alloc] initWithContentsOfURL:location];
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:nil];
self.photos = [responseDict valueForKeyPath:@"photo"];
NSLog(@"photo %@", self.photos);
}];
[task resume];
The problem part is that when I try to set the amount of cells it doesn't work because the property is empty.
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.photos count];
NSLog(@"photo %@", self.photos);
}
Can someone help me?
Kirill Pahnev
30 PointsFound the problem, I missed the dispatch_async part
Arman Kussainov
4,754 PointsArman Kussainov
4,754 PointsDid you receive any data from web?