Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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...