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 trialFrank Novello
19,299 PointsWhen creating a new instance of blogpost inside the didselectrowatindex path method. How does blogpost have blogposts?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { BlogPost *blogPost = [self.blogPosts objectAtIndex:indexPath.row]; NSLog(@"%@",blogPost.title);
} How come blogPost isn't just an empty object if it is a new instance of a BlogPost class created locally inside the function call?
1 Answer
Oliver Duncan
16,642 PointsAfter the view loads, our code creates an array, blogPosts array. Using a 'for in' loop, we create a new instance of a BlogPost for every post in the JSON data and add it to the array. Now the TableViewController has a property, blogPosts, that is an array of BlogPost instances. Thereafter (outside of that function) we instantiate a new instance of the BlogPost class and assign it to one of the instances in the blogPosts array.