6
votes

I have an iTunes style interface in my application: Source list (NSOutlineView) on the left that contains different libraries and playlists with an NSTableView on the right side of the interface displaying information for "Presentations". Similar to iTunes, I am showing the same type of information in the table view whether a library or playlist is selected (title, author, date created, etc).

alt text

I currently have an NSArrayController connected to my NSTableView and was setting the fetch predicate based on what was selected in the source list. This works fine when selecting a library because I can just set the fetch predicate to filter by the "type" field in my Presentation Core Data entity. When I try to adjust the fetch predicate for the playlist however, it doesn't look like there is any way to set the fetch predicate because I've got a table in between Playlists and Presentations to keep up with the order within the Playlist. According to the Apple docs, these type of predicates are not doable with Core Data (it basically doesn't multiple inner joins). Below is the relevant portion of my Data Model.

alt text

Is my data model setup incorrectly? Should I drop the NSArrayController and handle connecting the NSTableView up by hand? I'm trying to figure out if there is a simple fix, or really a design flaw.

1

1 Answers

0
votes

There is a documentation for creating relationships in CoreData

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/CoreData/Articles/cdBindings.html

But afais from your DB model, you are doing it right with three tables:

Presentation with info about song PlaylistItem with one-to-one relationship to Presentation Playlist with one-to-many relationship to PlaylistItem

Presentation [ID TITLE URL ALBUM ARTIST ....]
PlaylistItem [ID Presentation_ID Playlist_ID]
Playlists [ID Title MoreInfo]

So in language of IB CoreData implementation:

  • Start with fetching out every Playlist to NSOutlineView in left column
  • On select, get Playlist ID and Fetch all PlaylistItem based on Playlist_ID filtering
  • PlaylistItem will have Presentation object inside to access releated song info

And yes, if I were you, I would preffer to take care about connecting nstableview by hand