MPMediaQuery
A query that specifies a set of media items from the device’s media library using a filter and a grouping type.
Declaration
class MPMediaQueryMentioned in
Overview
Filter and grouping types are both optional; an unqualified query matches the entire library.
A query has at most one grouping type. A query’s filter can consist of any number of media property predicates. You build filters using MPMediaPropertyPredicate objects, based on property keys described in MPMediaItem.
After creating and configuring a query, you use it to retrieve media items or media item collections. You can also use a query to retrieve an array of MPMediaQuerySection instances, useful for displaying the results of a query in the user interface of your app. See the itemSections and collectionSections properties.
This class includes several convenience constructors that each apply a grouping type and, in most cases, match a subset of the library. The following table summarizes the features of these constructors. See MPMediaItem for descriptions of the entries in the Filter column. See MPMediaGrouping for descriptions of the entries in the Grouping type column.
Constructor name | Matches entire library | Filter | Grouping type |
|---|---|---|---|
- | |||
- | |||
- | |||
- | |||
Yes | |||
Yes | |||
Yes | |||
- | |||
- |
Topics
Creating media queries
albums()artists()songs()playlists()podcasts()audiobooks()compilations()composers()genres()init(filterPredicates:)
Configuring media queries
filterPredicatesaddFilterPredicate(_:)removeFilterPredicate(_:)groupingTypeitemSectionscollectionSectionsMPMediaGrouping