[英]Objective-C “<…>” notation
我正在閱讀《更多iPhone編程3》,我不記得<>表示法是什么。 我知道它符合一個類的協議,但是我不確定在此示例中“核心數據”部分中談論NSFetchedResultsController是什么。 這是代碼:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
謝謝!
id <NSFetchedResultsSectionInfo> sectionInfo
只是意味着sectionInfo
是符合NSFetchedResultsSectionInfo
協議的某個對象(由id
表示)。
通過將變量聲明為符合該協議的類型,可以確保可以使用其numberOfObjects
屬性,除非事實證明該對象不符合該協議,否則將導致崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.