CoreData、SourceList 和 NSTreeController
好的,伙计们,这是我的问题。
我将使用 CoreData + Source List + NSTreeController 创建类似于 Finder(或 iTunes,如果您愿意)的源列表的内容。
我的问题是我的源列表中的内容并不完全来自 CoreData。例如,我有一个名为“来自核心数据的数据”的部分(根),它是使用 CoreData 填充的,但我也有一些在运行时创建的“假”部分(即“收藏夹”部分)。
出于这个原因,我认为使用实体将 OutlineView 和 NSTreeController 直接绑定到 CoreData 是不可行的,我必须使用像 NSMutableArray 这样的中间东西,我在开始时使用来自 CoreData 的数据和使用 ad- 的“假”部分填充它。成员的特殊类(如 Apple 的“SourceView”示例)。这是第一个问题:(1)我这样做对吗?
我的第二个问题是关于这个 NSMutableArray 的。假设使用这个数组可能是一个解决方案,我想知道哪种是填充数组的正确方法。在示例“SourceView”中,中间数组是使用 NSTreeController (insertObject:) 在运行时填充的,但另一个解决方案我正在考虑继承 NSMutableArray 并直接更改数组的内容。 (2)我这样破坏MVC了吗?
Ok guys, here is my question.
I would use CoreData + Source List + NSTreeController to create something similar to the source list of Finder (or iTunes if you prefer).
My problem is that what I have in my source list doesn't come entirely from CoreData. For example I have a section (root) called "data from core data" that is populated using CoreData, but I also have some "fake" sections (i.e. "Favorites" section) that are created run-time.
For this reason I think that binding the OutlineView and the NSTreeController directly to CoreData using entities is not feasible and that I have to use something intermediate like a NSMutableArray that I populate at start with data coming from CoreData and the "fake" sections using ad-hoc classes for the members (like in the "SourceView" example by Apple). This is the first question: (1) Am I right in doing this?
My second question is about this NSMutableArray. Let's say that using this array could be a solution, I was wondering which is the correct way to fill the array in. In the example "SourceView" the intermediate array is populated run-time using the NSTreeController (insertObject:), but another solution I was thinking of is subclassing NSMutableArray and change directly the content of the array. (2) Am I breaking the MVC in this way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将持久节点与仅在运行时存在的临时节点混合的一种方法是将 NSInMemoryStoreType 存储添加到 persistenceStoreCoordinator。以下是有关如何执行此操作的教程: http://simplyhacking.com/source -list-with-core-data.html
One approach to mix persistent nodes with temporary nodes which only exist at runtime, is to add a NSInMemoryStoreType store to your persistentStoreCoordinator. Here is a tutorial on how to do this: http://simplyhacking.com/source-list-with-core-data.html