---
title: "fileImporter(isPresented:allowedContentTypes:onCompletion:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/fileimporter(ispresented:allowedcontenttypes:oncompletion:)"
---

# fileImporter(isPresented:allowedContentTypes:onCompletion:)

Presents a system dialog for allowing the user to import an existing file.

## Declaration

```swift
nonisolated func fileImporter(isPresented: Binding<Bool>, allowedContentTypes: [UTType], 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.
- `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.

## Discussion

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, an application can have a button that allows the user to choose the default directory with document templates loaded on every launch. Such a button might look like this:  struct PickTemplatesDirectoryButton: View {      @State private var showFileImporter = false      var onTemplatesDirectoryPicked: (URL) -> Void

var body: some View {          Button {              showFileImporter = true          } label: {              Label("Choose templates directory", systemImage: "folder.circle")          }          .fileImporter(              isPresented: $showFileImporter,              allowedContentTypes: [.directory]          ) { result in               switch result {               case .success(let directory):                   // gain access to the directory                   let gotAccess = directory.startAccessingSecurityScopedResource()                   if !gotAccess { return }                   // access the directory URL                   // (read templates in the directory, make a bookmark, etc.)                   onTemplatesDirectoryPicked(directory)                   // release access                   directory.stopAccessingSecurityScopedResource()               case .failure(let error):                   // handle error                   print(error)               }          }      }  } note: Changing allowedContentTypes 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(_:), fileDialogConfirmationLabel(_:), fileDialogMessage(_:), fileDialogBrowserOptions(_:), fileDialogURLEnabled(_:), fileDialogImportsUnresolvedAliases(_:), and fileDialogCustomizationID(_:).

## See Also

### Importing from file

- [fileImporter(isPresented:allowedContentTypes:allowsMultipleSelection:onCompletion:)](swiftui/view/fileimporter(ispresented:allowedcontenttypes:allowsmultipleselection:oncompletion:).md)
- [fileImporter(isPresented:allowedContentTypes:allowsMultipleSelection:onCompletion:onCancellation:)](swiftui/view/fileimporter(ispresented:allowedcontenttypes:allowsmultipleselection:oncompletion:oncancellation:).md)
