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 Diary App Using Core Data Listing Data using NSFetchedResultsController Fetched Results Controller

7,320 Points

Strange syntax: [self.fetchedResultsController sections][section]

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];//what is this syntax?
    return [sectionInfo numberOfObjects];


In this function, I do not understand what kind of syntax is this:

[self.fetchedResultsController sections][section]

Why is "section" itself in square brackets, what does it mean? I tried sending it as a message to .sections property, and it said that it's not implemented. Could you explain this piece of syntax please, how does it work and what it does, and perhaps give some example of usage in other situations?

7,320 Points

Hm, am I answering my own question again? It's shorthand syntax for accessing an object in an array, isn't it? =)

I think syntax like self.fetchedResultsController.sections[section] would be much clearer. I thought it was some esoteric method call first...