Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data - Order of objects in a to-many relationship

My app is a music library app, the user has their songs, and they can create playlists.
I want the order of the songs in the playlist to be in the order that the user adds those songs to that playlist.

My core data objects:

Song
=====
name
duration
album

artist (to one relationship)

Playlist
========
title

songs (to many relationship)  

I have a tableview of playlists, each row in that table shows the title of the playlist and the name of the last song added to that playlist.

I have two questions:

  1. How can i know what was the last song the user added to the playlist? even more how can I know the order of the songs in a given playlist?
  2. How should I fetch that last song name when i'm building the playlists tableview?
like image 572
Eyal Avatar asked Dec 11 '22 08:12

Eyal


1 Answers

Set the relationship type to ordered in the core data editor. This will mean that you now get an NSOrderedSet of songs instead of just an NSSet of songs

like image 56
Paul.s Avatar answered Dec 13 '22 23:12

Paul.s