DocumentPicker is a SwiftUI view modifier to show/hide the system's document picker. Fully compatible with the macOS, iOS, iPadOS and Mac Catalyst platforms.
struct ContentView: View {
@State var showDocPicker = false
var body: some View {
Button("Show document picker") {
self.showDocPicker.toggle()
}
.documentPicker(
isPresented: $showDocPicker,
documentTypes: ["public.folder"],
) { urls in
print("Selected folder: \(urls.first!)")
}
}
}
More info in the docs.
In XCode add the following URL to your project's Swift Package dependencies:
https://github.com/swiftuilib/document-picker
To modify the package contents while still being able to see SwiftUI Previews use the provided DocumentPickerPreview.xcodeproj
.