Cry*_*tal 0 iphone syntax objective-c ios
我正在阅读更多iPhone编程3,我不记得<>符号是什么.我知道这是符合协议的一类,但我不知道它是什么,在这个例子中的核心数据部分谈论NSFetchedResultsController.这是代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
Run Code Online (Sandbox Code Playgroud)
谢谢!
id <NSFetchedResultsSectionInfo> sectionInfo
简单地表示符合协议的sectionInfo
某个对象(表示为id
)NSFetchedResultsSectionInfo
.
通过将变量声明为符合此协议的类型,numberOfObjects
保证其属性可供使用,除非事实证明该对象不符合协议,在这种情况下您会遇到崩溃.