<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FileProvider",
  "identifier" : "/documentation/FileProvider/NSFileProviderManager/import(_:fromDirectoryAt:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "File Provider",
      "FileProvider"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileProviderManager(cm)importDomain:fromDirectoryAtURL:completionHandler:"
  },
  "title" : "import(_:fromDirectoryAt:completionHandler:)"
}
-->

# import(_:fromDirectoryAt:completionHandler:)

Creates a new domain that takes ownership of on-disk data that your app previously managed without a file provider.

```
class func `import`(_ domain: NSFileProviderDomain, fromDirectoryAt url: URL, completionHandler: @escaping @Sendable ((any Error)?) -> Void)
```

## Parameters

`domain`

The domain to import.

`url`

A URL that points to the directory to import.

`completionHandler`

A block that the system calls as soon as it creates the new domain. It takes the following parameters:

- `error`: If an error occurs, this object contains information about the error; otherwise, it’s `nil`.

## Discussion

> Important:
> You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration:
> 
> ```swift
> class func `import`(_ domain: NSFileProviderDomain, fromDirectoryAt url: URL) async throws
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

Use this method to migrate an existing file hierarchy on disk to a [`NSFileProviderExtension`](/documentation/FileProvider/NSFileProviderExtension) without redownloading the data. After you call the method, the provided URL is no longer valid. The system has moved and now manages all of its contents.

If a domain with the same name already exists, the method fails with an <doc://com.apple.documentation/documentation/Foundation/NSFileWriteFileExistsError-swift.var> error. The URL remains untouched. If the system doesn’t allow the extension to request a migration, the method fails with an <doc://com.apple.documentation/documentation/Foundation/NSFeatureUnsupportedError-swift.var> error.

The system starts by moving the provided directory into its local cache, and then calls the completion handler. Then, for each item in the directory, it calls your extension’s [`createItem(basedOn:fields:contents:options:request:completionHandler:)`](/documentation/FileProvider/NSFileProviderReplicatedExtension/createItem(basedOn:fields:contents:options:request:completionHandler:)) with the [`mayAlreadyExist`](/documentation/FileProvider/NSFileProviderCreateItemOptions/mayAlreadyExist) option.

When the import finishes, the system calls your extension’s [`importDidFinish(completionHandler:)`](/documentation/FileProvider/NSFileProviderReplicatedExtension/importDidFinish(completionHandler:)) method. If you call [`reimportItems(below:completionHandler:)`](/documentation/FileProvider/NSFileProviderManager/reimportItems(below:completionHandler:)) before the import finishes, the system makes a single call to [`importDidFinish(completionHandler:)`](/documentation/FileProvider/NSFileProviderReplicatedExtension/importDidFinish(completionHandler:)) for both imports.

---

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)