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

It's not been made clear what angle bracket declarations do? why do you use angle brackets instead of casting?

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultController sections] [section];

When should this type of declaration be used and why? What does it do?

1 Answer

Stone Preston
Stone Preston
42,016 Points

using <NSFetchedResultsSectionInfo> means the object is adhering to the NSFetchedResultsSectionInfo protocol.

You see this syntax a lot in class declarations. for example when working with a table view sometimes you need to conform to the data source and delegate protocols. so you see that listed after the class declaration:

@interface someViewCOntroller : UIViewController 
    <UITableViewDataSource, UITableViewDataDelegate>

the line

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultController sections] [section];

simply creates a generic object (type ID) and the <NSFetchedResultsSectionInfo> basicallyt says "this object is going to adhere to this protocol"

see the apple docs on working with protocols for more information