Carlo
Carlo

Reputation: 151

CoreData, SourceList and NSTreeController

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?

Upvotes: 2

Views: 662

Answers (1)

seb
seb

Reputation: 2385

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

Upvotes: 0

Related Questions