views:

43

answers:

2

Hi,

I am working on this core data app, and im not exactly shure how to do what i want.

Right now my first view displays a list of playlists. I can add a playlist to the list. The plus sign pops up addViewController. From here i can add a name to the playlist, now comes the tricky part for me..

I want to be able to select songs from a big list i have.

How do i set up this models?

I was thinking something like this:

|Entity:           Playlist |                        |Entity:           Song      |
|Attribute:       name   |                        |Attribute:       name     |
|Relationship: songs  |<<------------->>|Relationship: playlists |

I want songs to be in more than one playlist, sometimes more than once in a playlist, and I want to be able to add more songs to the database.

Anyone know some sample code that does this sort of thing, or give me some hints at how to do this?

+2  A: 

Adding a song to a playlist more than once is a bit tricky. First of all within a relationship you can define only one relation between two objects. Second you need to define some kind of sort index for multiple positions within a playlist

I would recommend adding another entity handling the relation between song and playlist (see image below, the sort index in Playlist is optional) Playlist - SongInPlaylist - Song

Martin Brugger
+1 for adding the relationship model diagram alone. Nicely done!
Joost Schuur
Thanks for the quick answer!How do i deal with the big songs db? Shoud i show a new view and add NSFetchedResultsControllerDelegate to that view as well as the rootView? then when ever a row is chosen send it to the selected playlist?
Larsaronen
A: 

I did add NSFetchedResultsControllerDelegate to a new view and send the song at the selected row to the playlist. Works fine now! thanks for the answer!

Larsaronen