Instance Method

resourceValues(forKeys:)

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

Declaration

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

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 resource value varies by resource property (see resource key definitions). If this method does not throw and the resulting value in the URLResourceValues is populated with nil, it means the resource property is not available for the specified resource and no errors occurred when determining the resource property was not available. This method is currently applicable only to URLs for file system resources.

When this function is used from the main thread, resource values cached by the URL (except those added as temporary properties) are removed the next time the main thread’s run loop runs. func removeCachedResourceValue(forKey:) and func removeAllCachedResourceValues() also may be used to remove cached resource values.

Only the values for the keys specified in keys will be populated.

See Also

Accessing Resource Values

func setResourceValues(URLResourceValues)

Sets the resource value identified by a given resource key.

func removeCachedResourceValue(forKey: URLResourceKey)

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

func removeAllCachedResourceValues()

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

func setTemporaryResourceValue(Any, forKey: URLResourceKey)

Sets a temporary resource value on the URL object.

struct URLResourceKey

Keys that apply to file system URLs.

struct URLResourceValues

The properties supported by file system resources.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software