A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.

Overview

Bookmark

A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.

Swift Package Manager

This class wraps Swift's URL bookmark functionality. See Apple's documentation for further information.

A 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.

A 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.

Some information links :-

Usage

Create and use a bookmark

// The original file url
let originalURL = URL(targetFileURL: ...)!

// Create a bookmark
let bookmark = try Bookmark(targetFileURL: originalURL)

// Access to the raw bookmark data
let bookmarkData = bookmark.bookmarkData

try bookmark.usingTargetURL { targetURL in
   // Do something with the targetURL which is the original URL
}

// ... Somewhere in here, the original url file is moved or renamed ...

try bookmark.usingTargetURL { targetURL in
   // Do something with the targetURL (which will correctly point to the new URL location)
}

Save/Load bookmark data

// The original file url
let originalURL = URL(targetFileURL: ...)!

// Create a bookmark
let bookmark = try Bookmark(targetFileURL: originalURL)

// Grab out the raw bookmark data
let storableData = bookmark.bookmarkData

// ...Save the bookmark data for later use, eg. in CoreData or in a database...

// Load the bookmark data back out from the storage medium...
let savedBookmarkData = <load bookmark data from somewhere>
// ... and recreate the Bookmark object from the data
let existingBookmark = try Bookmark(bookmarkData: savedBookmarkData)

// Use the loaded bookmark
try existingBookmark.usingTargetURL { targetURL in
   // ...Do something with the targetURL...
}

License

MIT. Use it for anything you want, just attribute my work if you do. Let me know if you do use it somewhere, I'd love to hear about it!

MIT License

Copyright (c) 2022 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Read iOS 15 privacy insight '.ndjson' file into your human brain.
Read iOS 15 privacy insight '.ndjson' file into your human brain.

Insight Read iOS 15 privacy insight '.ndjson' file into your human brain. Written in SwiftUI. Feature Compile records into app summary Relink app info

ALO sync allows you to sync resources form an ALO endpoint to your macOS file system.
ALO sync allows you to sync resources form an ALO endpoint to your macOS file system.

ALO sync allows you to sync resources form an ALO endpoint to your macOS file system. Prerequisites macOS 11 No support for search* No suppor

A library that helps developers to easily perform file-related operations In iOS

File Operations Preview A library that helps developers to easily perform file-related operations. In iOS, We write our files mainly into three direct

WordScramble app for demonstrating loading an external txt file and working with it
WordScramble app for demonstrating loading an external txt file and working with it

WordScramble-v2 WordScramble app for demonstrating loading an external txt file and working with it App for creating anagrams from given 8 letter word

Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings)

Swift .csv parser Taking a string containing a csv file and split it into records (aka lines) containing fields of data (aka Array of SubStrings). Par

Extracts the text from the Docx file

SNDocx Extracts the text from the Docx files and converts them into a valuable object that can be used Example To run the example project, clone the r

Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

💡 A light Swift wrapper around Objective-C Runtime
💡 A light Swift wrapper around Objective-C Runtime

A light wrapper around Objective-C Runtime. What exactly is lumos? lumos as mentioned is a light wrapper around objective-c runtime functions to allow

UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift.

UTIKit UTIKit is an UTI (Uniform Type Identifier) wrapper for Swift. Features UTIKit is a full featured library including entire UTI functions. Conver

Owner
Darren Ford
Darren Ford
Swift implementation of the package url spec

PackageURL Swift implementation of the package url specification. Requirements Swift 5.3+ Usage import PackageURL let purl: PackageURL = "pkg:swift/a

Mattt 21 Jun 14, 2022
Extensions that allow you to work with optionals

RxOptionals Sometimes it happens that you need to bind to several optional binders or to an optional method (for example, when using weak). To do this

Dane4ka 3 Aug 9, 2021
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.

Link Previewer for iOS, macOS, watchOS and tvOS It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.

Leonardo Cardoso 1.3k Jan 2, 2023
SMAP: Swiss Topo Map URL Generator

smap - Swiss Topo Map URL Generator Usage: smap [-b] <image-file-path> Reads fil

Jean-Nicolas 0 Dec 29, 2021
A Swift property wrapper which stores the previous value

swift-with-previous A Swift property wrapper which stores the previous value. The previous value can be get by the projected value $propertyName. impo

IKEDA Sho 3 Feb 22, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
Swift library and command line tool that interacts with the mach-o file format.

MachO-Reader Playground project to learn more about the Mach-O file format. How to run swift run MachO-Reader <path-to-binary> You should see a simila

Gonzalo 5 Jun 25, 2022
Mac app to change .ipa file app icons and display names

IPAEdit Mac app to change .ipa file app icon, display name, and app version to avoid updates Compatible with macOS 10.11+ Install To install either cl

Ethan Goodhart 23 Dec 28, 2022
.DS_Store file parser/viewer.

.DS_Store file parser/viewer.

JD Gadina 51 Dec 1, 2022
Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

Hans Knöchel 6 Jan 26, 2022