Instance Method


In an app that has adopted App Sandbox, makes the resource pointed to by a security-scoped URL available to the app.


func startAccessingSecurityScopedResource() -> Bool

Return Value

true if the request to access the resource succeeded; otherwise, false.


When you obtain a security-scoped URL, such as by resolving a security-scoped bookmark, you cannot immediately use the resource it points to. To make the resource available to your app, by way of adding its location to your app’s sandbox, call this method (or its Core Foundation equivalent, the CFURLStartAccessingSecurityScopedResource(_:) function) on the security-scoped URL.

If this method returns true, then you must relinquish access as soon as you finish using the resource. Call the stopAccessingSecurityScopedResource() method to relinquish access. When you call the stopAccessingSecurityScopedResource() method, you immediately lose access to the resource in question.

See Also

Working with Bookmark Data

class func bookmarkData(withContentsOf: URL) -> Data

Initializes and returns bookmark data derived from an alias file pointed to by a specified URL.

class func resourceValues(forKeys: [URLResourceKey], fromBookmarkData: Data) -> [URLResourceKey : Any]?

Returns the resource values for properties identified by a specified array of keys contained in specified bookmark data.

class func writeBookmarkData(Data, to: URL, options: NSURL.BookmarkFileCreationOptions)

Creates an alias file on disk at a specified location with specified bookmark data.

func stopAccessingSecurityScopedResource()

In an app that adopts App Sandbox, revokes access to the resource pointed to by a security-scoped URL.

typealias NSURL.BookmarkFileCreationOptions

Options used when creating file bookmark data

struct NSURL.BookmarkCreationOptions

Options used when creating bookmark data.

struct NSURL.BookmarkResolutionOptions

Options used when resolving bookmark data.