My core data model:
Playlist
=======
name
songs (to-many relationship to Song objects, NSOrderedSet)
A playlist has multiple songs, and the song order is important.
Using NSOrderedSet
I can keep the songs order, the problem is when I want to fetch and present a playlist's songs in a table view, I don't know how to use that advantage with a NSFetchRequest
.
This is how I fetch playlist's songs:
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Song"];
request.predicate = [NSPredicate predicateWithFormat:@"ANY playlists = %@", self.playlist];
request.sortDescriptors = // ???
request.fetchBatchSize = 20;
self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
Actually this won't work because the NSFetchedResultsController
requires a fetch request with sort descriptors.
So I have the songs order, but I can't fetch them according to that order?