<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/fileImporter(isPresented:allowedContentTypes:allowsMultipleSelection:onCompletion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE12fileImporter11isPresented19allowedContentTypes23allowsMultipleSelection12onCompletionQrAA7BindingVySbG_Say22UniformTypeIdentifiers6UTTypeVGSbys6ResultOySay10Foundation3URLVGs5Error_pGctF"
  },
  "title" : "fileImporter(isPresented:allowedContentTypes:allowsMultipleSelection:onCompletion:)"
}
-->

# fileImporter(isPresented:allowedContentTypes:allowsMultipleSelection:onCompletion:)

Presents a system dialog for allowing the user to import multiple
files.

```
nonisolated func fileImporter(isPresented: Binding<Bool>, allowedContentTypes: [UTType], allowsMultipleSelection: Bool, onCompletion: @escaping (Result<[URL], any Error>) -> Void) -> some View
```

## Parameters

`isPresented`

A binding to whether the dialog should be shown.

`allowedContentTypes`

The list of supported content types which can
be imported.

`allowsMultipleSelection`

Whether the importer allows the user to
select more than one file to import.

`onCompletion`

A callback that will be invoked when the operation has
succeeded or failed. To access the received URLs, call `startAccessingSecurityScopedResource`.
When the access is no longer required, call `stopAccessingSecurityScopedResource`.

- result: A `Result` indicating whether the operation succeeded or
  failed.

## Discussion

In order for the dialog to appear, `isPresented` must be `true`. When
the operation is finished, `isPresented` will be set to `false` before
`onCompletion` is called. If the user cancels the operation,
`isPresented` will be set to `false` and `onCompletion` will not be
called.

> Note: This dialog provides security-scoped URLs.
> Call the ``startAccessingSecurityScopedResource`` method to access or bookmark
> the URLs, and the ``stopAccessingSecurityScopedResource`` method
> to release the access.

For example, a button that allows the user to choose multiple PDF files for the application
to combine them later, might look like this:

```
   struct PickPDFsButton: View {
       @State private var showFileImporter = false
       var handlePickedPDF: (URL) -> Void

       var body: some View {
           Button {
               showFileImporter = true
           } label: {
               Label("Choose PDFs to combine", systemImage: "doc.circle")
           }
           .fileImporter(
               isPresented: $showFileImporter,
               allowedContentTypes: [.pdf],
               allowsMultipleSelection: true
           ) { result in
               switch result {
               case .success(let files):
                   files.forEach { file in
                       // gain access to the directory
                       let gotAccess = file.startAccessingSecurityScopedResource()
                       if !gotAccess { return }
                       // access the directory URL
                       // (read templates in the directory, make a bookmark, etc.)
                       handlePickedPDF(file)
                       // release access
                       file.stopAccessingSecurityScopedResource()
                   }
               case .failure(let error):
                   // handle error
                   print(error)
               }
           }
       }
   }
```

> Note: Changing `allowedContentTypes` or `allowsMultipleSelection`
> while the file importer is presented will have no immediate effect,
> however will apply the next time it is presented.

To further configure the dialog’s appearance and behavior, use these
view modifiers: [`fileDialogDefaultDirectory(_:)`](/documentation/SwiftUI/View/fileDialogDefaultDirectory(_:)),
[`fileDialogConfirmationLabel(_:)`](/documentation/SwiftUI/View/fileDialogConfirmationLabel(_:)), [`fileDialogMessage(_:)`](/documentation/SwiftUI/View/fileDialogMessage(_:)),
[`fileDialogBrowserOptions(_:)`](/documentation/SwiftUI/View/fileDialogBrowserOptions(_:)), [`fileDialogURLEnabled(_:)`](/documentation/SwiftUI/View/fileDialogURLEnabled(_:)),
[`fileDialogImportsUnresolvedAliases(_:)`](/documentation/SwiftUI/View/fileDialogImportsUnresolvedAliases(_:)), and
[`fileDialogCustomizationID(_:)`](/documentation/SwiftUI/View/fileDialogCustomizationID(_:)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)