The following code, is used to partition and add sections to a list of songs.
query = [MPMediaQuery songsQuery];
[query addFilterPredicate: artistNamePredicate];
NSArray *itemsFromArtistQuery = [query items];
self.artist1 = [self partitionObjects:itemsFromArtistQuery collationStringSelector:@selector(title)];
Works perfectly. However when I try to do it with:
query = [MPMediaQuery albumsQuery]; //same with playlistsQuery, artistsQuery, genresQuery
[query addFilterPredicate: artistNamePredicate];
NSArray *itemsFromArtistQuery = [query collections];
self.artist1 = [self partitionObjects:itemsFromArtistQuery collationStringSelector:@selector(title)];
I get a SIGABRT error every single time. I’ve attributed it to the “collections” part of the code, as that’s the only difference in the whole block. I’ve tried changing “title” to “name” “albumTitle”, “playlist”, “genre” and more, but I still end up with:
"-[MPConcreteMediaItemCollection title]: unrecognized selector sent to instance"
Can anybody help me here? I’m ready to rip my hair out!
THANK-YOU!
BenBen
You are right that the problem is with the collections part. The
collationStringSelector:must be a method that returns aNSStringfor the objects your passing it, in this caseMPMediaItemCollection‘s.(It worked in the first case because you were passing
MPMediaItem‘s which do respond totitle).Here we select each
MPMediaItemCollectionfrom theartistCollectionsarray and then get a singleMPMediaItemthat represents the whole collection. We can then get the artists name and add it to an array.Now we are passing an array of
NSString‘s so we set thecollationStringSelector:toselfwhich will return the artists name as aNSString.