TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Saving URL from selected Document via Document Picker

Forums > SwiftUI

Hello!

I have a document picker file below, how can I save the value from the variable "pdfStringPath"? I will need to pass this variable into another view and then save to core data. Might be as simple as a binding, but my mind is blanking! :

import Foundation
import SwiftUI
import UIKit

struct DocumentPicker: UIViewControllerRepresentable {

    @ObservedObject var license:License

    func makeCoordinator() -> DocumentPicker.Coordinator {
        return DocumentPicker.Coordinator(parent1: self)
    }

    func makeUIViewController(context: UIViewControllerRepresentableContext<DocumentPicker>) -> UIDocumentPickerViewController {
        let picker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
        picker.allowsMultipleSelection = false
        picker.delegate = context.coordinator
        return picker
    }

    func updateUIViewController(_ uiViewController: DocumentPicker.UIViewControllerType, context: UIViewControllerRepresentableContext<DocumentPicker>) {
    }

    class Coordinator: NSObject, UIDocumentPickerDelegate {

        var parent: DocumentPicker

        init(parent1: DocumentPicker){
            parent = parent1

        }
        func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
            //the line below opens up the pdf for viewing via quicklook
            //parent.filePath = urls[0]

            //how can i move this variable outside to my licensedetailsView?
            var pdfStringPath = urls[0].absoluteString
            print(pdfStringPath)

        }

    }

}

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

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.