---
title: "libraryWithAPIVersion:error:"
framework: iTunes Library
role: symbol
role_heading: Type Method
platforms: [Mac Catalyst 14.0+, macOS 10.13+]
path: "ituneslibrary/itlibrary/librarywithapiversion:error:"
---

# libraryWithAPIVersion:error:

Creates and initializes an instance of ITLibrary that can retrieve media entities.

## Declaration

```occ
+ (instancetype) libraryWithAPIVersion:(NSString *) requestedAPIVersion error:(NSError **) error;
```

## Parameters

- `requestedAPIVersion`: The version of the iTunesLibrary API that the app is requesting. Provide "1.0" if unknown.
- `error`: A pointer to a variable that receives an doc://com.apple.documentation/documentation/Foundation/NSError if this method fails. Can be nil if the error isn’t applicable to the caller.

## Return Value

Return Value An ITLibrary instance that can retrieve media entities, or nil if the method fails.

## Discussion

Discussion During initialization of the ITLibrary class, the system reads and parses the default iTunes database for the current user. All media entities cache in memory until deallocation of the object occurs. Listing 1. #import <iTunesLibrary/ITLibrary.h>   NSError * error = nil; ITLibrary* library = [libraryWithAPIVersion:@"1.0" error:&error]; if (library) {   NSArray playlists = library.allPlaylists; //  <- NSArray of ITLibPlaylist   NSArray mediaItems = library.allMediaItems; //  <- NSArray of ITLibMediaItem }

## See Also

### Essentials

- [init(apiVersion:)](ituneslibrary/itlibrary/init(apiversion:)-71e74.md)
- [init(apiVersion:options:)](ituneslibrary/itlibrary/init(apiversion:options:)-9eorg.md)
- [libraryWithAPIVersion:options:error:](ituneslibrary/itlibrary/librarywithapiversion:options:error:.md)
- [ITLibInitOptions](ituneslibrary/itlibinitoptions.md)
