<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/resourceValues(forKeys:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV14resourceValues7forKeysAA011URLResourceD0VShySo16NSURLResourceKeyaG_tKF"
  },
  "title" : "resourceValues(forKeys:)"
}
-->

# resourceValues(forKeys:)

Returns a collection of resource values identified by the given resource keys.

```
func resourceValues(forKeys keys: Set<URLResourceKey>) throws -> URLResourceValues
```

## Parameters

`keys`

A set of URL resource keys indicating the values to retrieve.

## Return Value

A [`URLResourceValues`](/documentation/Foundation/URLResourceValues) instance, containing the retrieved values.

## Discussion

This method first checks if the URL instance already caches the specified resource values. If so, it returns the cached resource values to the caller. If not, then this method synchronously obtains the resource values from the backing store, adds them to the URL object’s cache, and returns a populated [`URLResourceValues`](/documentation/Foundation/URLResourceValues) instance. This method only populates [`URLResourceValues`](/documentation/Foundation/URLResourceValues) members corresponding to the contents of the `keys` parameter.

The type of the returned resource value varies by resource property; for details, see the documentation for the [`URLResourceKey`](/documentation/Foundation/URLResourceKey) you want to access.

If there’s no available value for a given key in `keys`, the returned [`URLResourceValues`](/documentation/Foundation/URLResourceValues) contains `nil` for the corresponding item. If this method fails to determine a value’s availability or retrieve its value, the method throws an error.

When you call this method from the main thread, the URL removes cached resource values the next time the thread’s run loop runs, except those added as temporary properties. You can explicitly remove cached resource values with [`removeCachedResourceValue(forKey:)`](/documentation/Foundation/URL/removeCachedResourceValue(forKey:)) and [`removeAllCachedResourceValues()`](/documentation/Foundation/URL/removeAllCachedResourceValues()).

> Note:
> This method is currently applicable only to URLs for file system resources.

---

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)