<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MediaPlayer",
  "identifier" : "/documentation/MediaPlayer/MPMediaQuery/collections",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Media Player"
    ],
    "preciseIdentifier" : "c:objc(cs)MPMediaQuery(py)collections"
  },
  "title" : "collections"
}
-->

# collections

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

```
var collections: [MPMediaItemCollection]? { get }
```

## Discussion

The system groups and sorts the returned array of collections by the `groupingType` of the media query. The following code listing demonstrates how to use this property:

```swift
// Specify a media query. This one matches the entire library because it
// doesn't contain a media property predicate.
let everything = MPMediaQuery()
 
// Configure the media query to group its media items; here, grouped by artist.
everything.groupingType = MPMediaGrouping.artist
 
// Obtain the media item collections from the query.
let collections = [everything]
```

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 system sorts elements of the array by the artist name.

For the available grouping types, see [`MPMediaGrouping`](/documentation/MediaPlayer/MPMediaGrouping).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)