You could use the collectionSections
property on MPMediaQuery
to get the relevant section of your data. For the artistsQuery
, the title
of each MPMediaQuerySection
represents the first letter of an artist name. Each section also has a range
, which you could then apply to get a subarray of artist names from the collections
array.
This will give you the MPMediaQuerySection
for the letter A:
MPMediaQuery *allArtistsQuery = [MPMediaQuery artistsQuery];
NSArray *collectionSections = allArtistsQuery.collectionSections;
NSPredicate *artistPredicate = [NSPredicate predicateWithFormat:@"title == %@", @"A"];
MPMediaQuerySection *artistSection = [[collectionSections filteredArrayUsingPredicate:artistPredicate] lastObject];
Then take the range
property of that section to get a subarray of all artist collections starting with the letter A:
NSArray *collections = allArtistsQuery.collections;
NSRange arraySlice = artistSection.range;
NSArray *filteredCollections = [collections subarrayWithRange:arraySlice];
for (MPMediaItemCollection *artistCollection in filteredCollections) {
NSLog(@"%@", [[artistCollection representativeItem] valueForProperty:MPMediaItemPropertyArtist]);
}