Instance Property

collections

An array of media item collections whose contained items match the query’s media property predicate.

Declaration

@property(nonatomic, readonly) NSArray<MPMediaItemCollection *> *collections;

Discussion

The returned array of collections are grouped and sorted by the groupingType of the media query. The following code snippet illustrates how to use this property:

// Specify a media query; this one matches the entire library because it
// does not contain a media property predicate
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
 
// Configure the media query to group its media items; here, grouped by artist
[everything setGroupingType: MPMediaGroupingArtist];
 
// Obtain the media item collections from the query
NSArray *collections = [everything collections];

Each element of the collections array now contains a media item collection. Each collection contains the media items from the library by a particular artist. The elements of the array are sorted by artist name.

For the available grouping types, see MPMediaGrouping.

See Also

Performing Media Queries

items

An array of media items that match the media query’s predicate.