Hello everyone,
a a few days ago I coded a file picker struct in UIKit and it was working fine, the app I implemented it in even ran on my device no problems. Now all of a sudden, it gives me errors (Type 'FilePicker' does not conform to protocol 'UIViewControllerRepresentable'
) and refuses to compile. I changed absolutely nothing in the file...
Does anybody know why this is giving errors all of a sudden?
import SwiftUI
import UIKit
struct FilePicker: UIViewControllerRepresentable {
@Binding var isShown: Bool
@Binding var fileURL: URL?
func makeUIViewController(context: UIViewControllerRepresentableContext<FilePicker>) -> UIDocumentPickerViewController {
let picker = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .import)
picker.delegate = context.coordinator
return picker
}
func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: UIViewControllerRepresentableContext<FilePicker>) {
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, UIDocumentPickerDelegate {
var parent: FilePicker
init(_ parent: FilePicker) {
self.parent = parent
}
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
parent.fileURL = urls[0]
parent.isShown = false
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
parent.isShown = false
}
}
}