---
title: "getResourceValue(_:forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurl/getresourcevalue(_:forkey:)"
---

# getResourceValue(_:forKey:)

Returns the value of the resource property for the specified key.

## Declaration

```swift
func getResourceValue(_ value: AutoreleasingUnsafeMutablePointer<AnyObject?>, forKey key: URLResourceKey) throws
```

## Parameters

- `value`: The location where the value for the resource property identified by key should be stored.
- `key`: The name of one of the URL’s resource properties.

## Discussion

Discussion This method first checks if the URL object already caches the resource value. If so, it returns the cached resource value to the caller. If not, then this method synchronously obtains the resource value from the backing store, adds the resource value to the URL object’s cache, and returns the resource value to the caller. The type of the returned resource value varies by resource property; for details, see the documentation for the key you want to access. If this method returns true and the value is populated with nil, it means that the resource property is not available for the specified resource, and that no errors occurred when determining that the resource property was unavailable. If this method returns false, an error occurred. The object pointer referenced by error is populated with additional information. note: This method applies only to URLs that represent file system resources. note: In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Accessing Resource Values

- [resourceValues(forKeys:)](foundation/nsurl/resourcevalues(forkeys:).md)
- [setResourceValue(_:forKey:)](foundation/nsurl/setresourcevalue(_:forkey:).md)
- [setResourceValues(_:)](foundation/nsurl/setresourcevalues(_:).md)
- [removeAllCachedResourceValues()](foundation/nsurl/removeallcachedresourcevalues().md)
- [removeCachedResourceValue(forKey:)](foundation/nsurl/removecachedresourcevalue(forkey:).md)
- [setTemporaryResourceValue(_:forKey:)](foundation/nsurl/settemporaryresourcevalue(_:forkey:).md)
- [URLResourceKey](foundation/urlresourcekey.md)
