<!--
{
  "documentType" : "article",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/checking-volume-storage-capacity",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Checking Volume Storage Capacity"
}
-->

# Checking Volume Storage Capacity

Confirm that you have enough local storage space for a large amount of data.

## Discussion

Before you try to store a large amount of data locally, first verify that you have sufficient storage capacity. To get the storage capacity of a volume, you construct a URL (using an instance of [`URL`](/documentation/Foundation/URL))  that references an object on the volume to be queried, and then query that volume.

### Decide Which Query Type to Use

The query type to use depends on what’s being stored. If you’re storing data based on a user request or resources the app requires to function properly (for example, a video the user is about to watch or resources that are needed for the next level in a game), query against [`volumeAvailableCapacityForImportantUsageKey`](/documentation/Foundation/URLResourceKey/volumeAvailableCapacityForImportantUsageKey). However, if you’re downloading data in a more predictive manner (for example, downloading a newly available episode of a TV series that the user has been watching recently), query against [`volumeAvailableCapacityForOpportunisticUsageKey`](/documentation/Foundation/URLResourceKey/volumeAvailableCapacityForOpportunisticUsageKey).

### Construct a Query

Use this example as a guide to construct your own query:

```objc
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:@"/"];
NSError *error = nil;
NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
if (!results) {
    NSLog(@"Error retrieving resource keys: %@\n%@", [error localizedDescription], [error userInfo]);
    abort();
}
NSLog(@"Available capacity for important usage: %@", results[NSURLVolumeAvailableCapacityForImportantUsageKey]);
```

---

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)