{"id":18031754,"url":"https://github.com/dagronf/bookmark","last_synced_at":"2025-03-27T05:30:58.728Z","repository":{"id":52339574,"uuid":"519027292","full_name":"dagronf/Bookmark","owner":"dagronf","description":"A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.","archived":false,"fork":false,"pushed_at":"2024-07-28T09:51:18.000Z","size":35,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T04:31:40.135Z","etag":null,"topics":["bookmark","file","securityscope","swift","url"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dagronf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-29T00:04:29.000Z","updated_at":"2025-03-18T22:55:06.000Z","dependencies_parsed_at":"2024-07-28T08:55:29.220Z","dependency_job_id":"5ffb0113-8dec-481e-b20e-63bd5e23d85f","html_url":"https://github.com/dagronf/Bookmark","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FBookmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FBookmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FBookmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FBookmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/Bookmark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791341,"owners_count":20672665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bookmark","file","securityscope","swift","url"],"created_at":"2024-10-30T10:10:40.295Z","updated_at":"2025-03-27T05:30:57.903Z","avatar_url":"https://github.com/dagronf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bookmark\n\nA Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/v/tag/dagronf/Bookmark\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-lightgrey\" /\u003e\n    \u003ca href=\"https://swift.org/package-manager\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat\" alt=\"Swift Package Manager\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/macOS-10.11+-red\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/iOS-11+-blue\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/tvOS-11+-orange\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/watchOS-4+-purple\" /\u003e\n\u003c/p\u003e\n\nThis class wraps Swift's URL `bookmark` functionality. See [Apple's documentation](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10) for further information.\n\nA bookmark can be stored (eg. on disk, in a database etc.) and reloaded and it will be able to locate the original target for the bookmark, even it has been moved or renamed.\n\nA bookmark is an opaque data structure, enclosed in a `Data` object, that describes the location of a file. Whereas path and file reference URLs are potentially fragile between launches of your app, a bookmark can usually be used to re-create a URL to a file even in cases where the file was moved or renamed.\n\nSome information links :-\n\n* [Locating Files Using Bookmarks](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/AccessingFilesandDirectories/AccessingFilesandDirectories.html#//apple_ref/doc/uid/TP40010672-CH3-SW10)\n* [Enabling Security-Scoped Bookmark and URL Access](https://developer.apple.com/documentation/professional_video_applications/fcpxml_reference/asset/media-rep/bookmark/enabling_security-scoped_bookmark_and_url_access)\n* [Bookmarks and Security Scope](https://developer.apple.com/documentation/foundation/nsurl#1663783)\n\n## Usage\n\n### Create and use a bookmark\n\n```swift\n// The original file url\nlet originalURL = URL(targetFileURL: ...)!\n\n// Create a bookmark\nlet bookmark = try Bookmark(targetFileURL: originalURL)\n\n// Extension on URL to generate a bookmark\nlet bookmark2 = try originalURL.bookmark()\n\n// Access to the raw bookmark data\nlet bookmarkData = bookmark.bookmarkData\n\n// Resolve the bookmark and retrieve its state and target url\nlet resolved = try bookmark.resolved()\n\ntry bookmark.resolving { resolvedItem in\n   // Do something with the resolvedItem which is the original URL and its state\n}\n\n// ... Somewhere in here, the original url file is moved or renamed ...\n\ntry bookmark.resolving { resolvedItem in\n   // Do something with the resolvedItem (which will correctly point to the new URL location)\n}\n```\n\n### Save/Load bookmark data\n\n`Bookmark` fully supports the `Codable` protocol.\n\n```swift\n// The original file url\nlet originalURL = URL(targetFileURL: ...)!\n\n// Create a bookmark\nlet bookmark = try Bookmark(targetFileURL: originalURL)\n\n// Grab out the raw bookmark data\nlet storableData = bookmark.bookmarkData\n\n// ...Save the bookmark data for later use, eg. in CoreData or in a database...\n\n// Load the bookmark data back out from the storage medium...\nlet savedBookmarkData = \u003cload bookmark data from somewhere\u003e\n// ... and recreate the Bookmark object from the data\nlet existingBookmark = try Bookmark(bookmarkData: savedBookmarkData)\n\n// Use the loaded bookmark\ntry existingBookmark.resolving { resolved in\n   // ...Do something with the resolved bookmark URL\n}\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2024 Darren Ford\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fbookmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Fbookmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fbookmark/lists"}