<!--
{
  "availability" : [
    "iOS: 15.0.0 - 18.0.0",
    "iPadOS: 15.0.0 - 18.0.0",
    "macCatalyst: 15.0.0 - 18.0.0",
    "macOS: 12.0.0 - 15.0.0",
    "tvOS: 15.0.0 - 18.0.0",
    "visionOS: 1.0.0 - 2.0.0",
    "watchOS: 8.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "ShazamKit",
  "identifier" : "/documentation/ShazamKit/SHMediaLibrary/add(_:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ShazamKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SHMediaLibrary(im)addMediaItems:completionHandler:"
  },
  "title" : "add(_:completionHandler:)"
}
-->

# add(_:completionHandler:)

Adds an array of songs to the user’s Shazam library.

```
func add(_ mediaItems: [SHMediaItem], completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

```
func add(_ mediaItems: [SHMediaItem]) async throws
```

## Parameters

`mediaItems`

An array of media items that represents the songs to add to the library.

`completionHandler`

The system calls this completion block after adding the media items to the library.

    This block takes the following parameters:

- `error`: An error object if a problem occurs when adding any item; otherwise, `nil`.

## Discussion

> Important:
> You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration:
> 
> ```swift
> func add(_ mediaItems: [SHMediaItem]) async throws
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

Saving a song to the user’s Shazam library also saves the following media item properties and their associated values:

- [`shazamID`](/documentation/ShazamKit/SHMediaItemProperty/shazamID)
- [`title`](/documentation/ShazamKit/SHMediaItemProperty/title)
- [`subtitle`](/documentation/ShazamKit/SHMediaItemProperty/subtitle), or [`artist`](/documentation/ShazamKit/SHMediaItemProperty/artist) if the subtitle is unavailable

> Note:
> Saving to the user’s Shazam library works only for songs with a valid ``doc://com.apple.shazamkit/documentation/ShazamKit/SHMediaItemProperty/shazamID``.

---

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)