UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

fileImporter relative URL

Forums > SwiftUI

I want to save the URL of an iCloud Document in an CoreData Object. In order to pick the file i use the following code:

.fileImporter(
                isPresented: $isImporting,
                allowedContentTypes: [.jpeg, .png],
                allowsMultipleSelection: false
            ) { result in
                do {
                    let selectedFile : URL = try result.get().first!
                    if (FileManager.default.isUbiquitousItem(at: selectedFile)) {
                        /* USE URL */
                    }else{
                        /* ERROR ALERT Not an iCloud FIle */
                    }
                }catch{
                    /* ERROR Handling */
                }

            }

The result now contains a absolute URL like:

file:///Users/USER/Library/Developer/CoreSimulator/Devices/SIMULATOR_DEVICE_ID/data/Library/Mobile%20Documents/com~apple~CloudDocs/Folder/File.png

Is there a standardized way to convert this URL into the following relative iCloud Documents Path: "Folder/File.png"?

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.