<!--
{
  "availability" : [
    "macCatalyst: 14.0.0 -",
    "macOS: 10.13.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "iTunesLibrary",
  "identifier" : "/documentation/iTunesLibrary/ITLibMediaItem/location",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "iTunes Library"
    ],
    "preciseIdentifier" : "c:objc(cs)ITLibMediaItem(py)location"
  },
  "title" : "location"
}
-->

# location

The location of the media item on disk.

```
var location: URL? { get }
```

## Discussion

If the location of the media item isn’t available, this property returns [`ITLibMediaItemLocationType.unknown`](/documentation/iTunesLibrary/ITLibMediaItemLocationType/unknown).

This method returns URLs that are outside of the default sandbox. To use the iTunesLibrary framework, a sandboxed app must have the <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.security.assets.music.read-write> or <doc://com.apple.documentation/documentation/BundleResources/Entitlements/com.apple.security.assets.music.read-only> entitlement.

To access the media item file in a sandboxed app, call <doc://com.apple.documentation/documentation/Foundation/NSURL/startAccessingSecurityScopedResource()>.

Listing 1.

```objc
#import <iTunesLibrary/ITLibrary.h>
#import <iTunesLibrary/ITLibMediaItem.h>
 
// Initialize
    NSError * error = nil;
    ITLibrary* library =
        [[ITLibrary alloc] initWithAPIVersion:@"1.0" error:&error];
    if (library)
    {
        // Get first media item in the library
        NSArray * mediaItems = library.allMediaItems;
        if (mediaItems.count > 0)
        {
            // Get the location (URL) of the first media item and
            // prepare it for file read/write access.
            ITLibMediaItem * mediaItem =
                (ITLibMediaItem*)[mediaItems objectAtIndex:0];
            NSURL * mediaItemLocation = mediaItem.location;
 
            if (mediaItemLocation &&
                [mediaItemLocation startAccessingSecurityScopedResource])
            {
                // mediaItemLocation can be now used to read/write
                // the media file
                [mediaItemLocation stopAccessingSecurityScopedResource];
            }
        }
    }
```

For more information about using URLs that are outside the default sandbox from a sandboxed app, see [Security-Scoped Bookmarks and Persistent Resource Access](https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW16).

In nonsandboxed apps, you can use the returned location URL to access the media item file directly.

---

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)