iOS Development

swift – Modifying a file saved as bookmarkData in iOS SwiftUI

Spread the love

I’m selecting a dropbox file and saving it as a bookmark utilizing bookmarkData in my iOS app. It really works completely

 func addBookmark(for url: URL) {
        do {
            // Begin accessing a security-scoped useful resource.
            guard url.startAccessingSecurityScopedResource() else {
                // Deal with the failure right here.
            // Ensure you launch the security-scoped useful resource once you end.
            defer { url.stopAccessingSecurityScopedResource() }
            // Convert URL to bookmark
            let bookmarkData = strive url.bookmarkData(choices: .minimalBookmark, includingResourceValuesForKeys: [ .contentModificationDateKey], relativeTo: nil)
            strive bookmarkData.write(to: getAppSandboxDirectory().appendingPathComponent("filePath"))
            // Add the URL and UUID to the urls array
            withAnimation {
        catch {
            // Deal with the error right here.

Then I modify that file, for instance add a brand new line to the textual content file in dropbox. File syncs to my gadget. (If I open it from information app I can see the modified knowledge).

However after I resolve the bookmarked url and look at it in my app, it exhibits outdated model of the file. Not the modified one with the brand new knowledge.

func loadAllBookmarks() {
        // Get all of the bookmark information
        let information = strive? FileManager.default.contentsOfDirectory(at: getAppSandboxDirectory(), includingPropertiesForKeys: nil)
        // Map over the bookmark information
        self.urls = information?.compactMap { file in
            do {
                let bookmarkData = strive Knowledge(contentsOf: file)
                var isStale = false
                // Get the URL from every bookmark
                let url = strive URL(resolvingBookmarkData: bookmarkData, bookmarkDataIsStale: &isStale)
                guard !isStale else {
                    // Deal with stale knowledge right here.
                    return nil
                // Return URL
                return url
            catch let error {
                // Deal with the error right here.
                return nil
        } ?? []

Edit: Additionally if I open the file picker from my app once more it exhibits the cloud downloadable icon and it mechanically downloads the file, with out even selecting the file.

Then I closed the file picker and that i may see the file was up to date in my app too. However I need to do it with out let the person select the file once more,

7 thoughts on “swift – Modifying a file saved as bookmarkData in iOS SwiftUI

  1. I have read some excellent stuff here Definitely value bookmarking for revisiting I wonder how much effort you put to make the sort of excellent informative website

  2. Excellent blog here Also your website loads up very fast What web host are you using Can I get your affiliate link to your host I wish my web site loaded up as quickly as yours lol

  3. I loved even more than you could possibly be able to accomplish right here. The picture is beautiful, and your language is elegant; yet, it appears that you are rushing through it, and I believe that you ought to give it another shot in the near future. That is something that I will most likely do again and again if you protect this hike.

  4. I was recommended this website by my cousin I am not sure whether this post is written by him as nobody else know such detailed about my trouble You are amazing Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *