简体   繁体   English

Objective-C“ <…>”表示法

[英]Objective-C “<…>” notation

I'm reading through More iPhone Programming 3, and I cannot remember what the <> notation is. 我正在阅读《更多iPhone编程3》,我不记得<>表示法是什么。 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. 我知道它符合一个类的协议,但是我不确定在此示例中“核心数据”部分中谈论NSFetchedResultsController是什么。 Here is the code: 这是代码:

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

Thanks! 谢谢!

id <NSFetchedResultsSectionInfo> sectionInfo simply means sectionInfo is some object (indicated by id ) that conforms to the NSFetchedResultsSectionInfo protocol. id <NSFetchedResultsSectionInfo> sectionInfo只是意味着sectionInfo是符合NSFetchedResultsSectionInfo协议的某个对象(由id表示)。

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. 通过将变量声明为符合该协议的类型,可以确保可以使用其numberOfObjects属性,除非事实证明该对象不符合该协议,否则将导致崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM