NSFetchedResultsController - 新语法?
我今天开始阅读有关 NSFetchedResultsController 的内容,但遇到了一些令人困惑的语法,有人可以描述一下以下两行的含义吗?特别是 id
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
另外
NSManagedObjectContext *context = <#Managed object context#>;
,请确认我的理解,NSFetchedResultsController 只是一种 NSMutableArray,但具有专门用于控制核心数据的附加功能(委托消息)?
I started reading up about the NSFetchedResultsController today, but I've come across some confusing syntax, can someone please describe what the following two lines mean? Specifically the id <something>
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
and
NSManagedObjectContext *context = <#Managed object context#>;
Also, please confirm my understanding that the NSFetchedResultsController is simply a kind of NSMutableArray but with additional functionality (delegate messages) specifically for controlling Core Data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
id<原型> foo
声明了一个变量foo
,其类型是“指向符合协议PROTO的对象的指针”。这意味着只能将PROTO
协议中的消息发送到foo
。<#Managed Object Context#>
不是有效的 Objective-C 语法。它只是说,“粘贴代码以获取对您的 MOC 的引用。”NSFetchedResultsController
与NSMutableArray
无关。它们唯一的共同点是都提供对有序集合的访问。NSFetchedResultsController
位于您和托管对象上下文之间。其内容取决于上下文中的内容以及创建获取结果控制器时提供的获取请求。它调解对 MOC 的访问并尽可能使用缓存的数据。它的预期用途是作为一种将数据从 Core Data 获取到 UITableView 的简单方法。id<PROTO> foo
declares a variablefoo
whose type is "pointer to object conforming to protocol PROTO". This means that it is only okay to send the messages in thePROTO
protocol tofoo
.<#Managed Object Context#>
is not valid Objective-C syntax. It's just saying, "stick the code to get a reference to your MOC here."NSFetchedResultsController
is not related toNSMutableArray
. The only thing they have in common is that both provide access to ordered collections.NSFetchedResultsController
stands between you and managed object context. Its content is determined by what is in the context and the fetch request supplied when the fetched results controller is created. It mediates access to the MOC and uses cached data whenever possible. Its intended use is as an easy way to get data from Core Data into aUITableView
.