Skip to content

Instantly share code, notes, and snippets.

@delasign
Created October 25, 2024 18:11
Show Gist options
  • Save delasign/c8a86aeffe03d836381bbd02c2d10848 to your computer and use it in GitHub Desktop.
Save delasign/c8a86aeffe03d836381bbd02c2d10848 to your computer and use it in GitHub Desktop.
Sample code for creating a bookmark with a security scope in Swift
import Foundation
func createSecurityScopedBookmark(for url: URL) -> Data? {
do {
// Create a bookmark from the selected URL
let bookmarkData = try url.bookmarkData(options: .securityScopeAllowOnlyReadAccess, includingResourceValuesForKeys: nil, relativeTo: nil)
debugPrint("\(DebuggingIdentifiers.actionOrEventSucceded) createSecurityScopedBookmark - \(bookmarkData)")
return bookmarkData
} catch {
debugPrint("\(DebuggingIdentifiers.actionOrEventFailed) createSecurityScopedBookmark error \(error)")
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment