Instance Method

getResourceValue:forKey:error:

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

Declaration

- (BOOL)getResourceValue:(out id  _Nullable *)value forKey:(NSURLResourceKey)key error:(out NSError * _Nullable *)error;

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.

error

The error that occurred if the resource value could not be retrieved. This parameter is optional. If you are not interested in receiving error information, you can pass nil.

Return Value

YES if value is successfully populated; otherwise, NO.

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 YES 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 NO, an error occurred. The object pointer referenced by error is populated with additional information.

See Also

Accessing Resource Values

- resourceValuesForKeys:error:

Returns the resource values for the properties identified by specified array of keys.

- setResourceValue:forKey:error:

Sets the URL’s resource property for a given key to a given value.

- setResourceValues:error:

Sets the URL’s resource properties for a given set of keys to a given set of values.

- removeAllCachedResourceValues

Removes all cached resource values and temporary resource values from the URL object.

- removeCachedResourceValueForKey:

Removes the cached resource value identified by a given key from the URL object.

- setTemporaryResourceValue:forKey:

Sets a temporary resource value on the URL object.

NSURLResourceKey

Keys that apply to file system URLs.