Crystal
Crystal

Reputation: 29468

Objective-C "<...>" notation

I'm reading through More iPhone Programming 3, and I cannot remember what the <> notation is. I know it's to conform to Protocols for a class, but I'm not sure what it is in this example talking about NSFetchedResultsController in the Core Data section. Here is the code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];

Thanks!

Upvotes: 0

Views: 166

Answers (1)

BoltClock
BoltClock

Reputation: 723729

id <NSFetchedResultsSectionInfo> sectionInfo simply means sectionInfo is some object (indicated by id) that conforms to the NSFetchedResultsSectionInfo protocol.

By declaring the variable as a type that conforms to this protocol, its numberOfObjects property is guaranteed to be available to use, unless it turns out the object doesn't conform to the protocol in which case you get a crash.

Upvotes: 7

Related Questions