<!--
{
  "availability" : [
    "iOS: 11.0.0 -",
    "iPadOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FileProvider",
  "identifier" : "/documentation/FileProvider/NSFileProviderExtension/setLastUsedDate(_:forItemIdentifier:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "File Provider",
      "FileProvider"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileProviderExtension(im)setLastUsedDate:forItemIdentifier:completionHandler:"
  },
  "title" : "setLastUsedDate(_:forItemIdentifier:completionHandler:)"
}
-->

# setLastUsedDate(_:forItemIdentifier:completionHandler:)

Marks an item as recently used and sets its relative order in the Recents list.

```
func setLastUsedDate(_ lastUsedDate: Date?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
```

```
func setLastUsedDate(_ lastUsedDate: Date?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem
```

## Parameters

`lastUsedDate`

The date and time when the item was last used. This value is used as the sort key for the Recents list.

`itemIdentifier`

The item’s persistent identifier.

`completionHandler`

A block that takes the following parameters:

- `recentlyUsedItem`: A file provider item that represents the changed item, or `nil` if an error occurred.
- `error`: An error object. If an error occurs, pass in an object that describes the error; otherwise, set it to `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
> func setLastUsedDate(_ lastUsedDate: Date?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

This method is called after the item is accessed by the host app. Override this method to make any necessary local changes. Your implementation should return immediately. Call the completion handler before performing any network activity or other long-running tasks. Defer these tasks to the background.

The `recentlyUsedItem` instance that you pass to the completion handler should match the item’s old file provider item, with only one change: set the item’s [`lastUsedDate`](/documentation/FileProvider/NSFileProviderItemProtocol/lastUsedDate) property with the value of the `lastUsedDate` parameter

Always include Items with a non-`nil` [`lastUsedDate`](/documentation/FileProvider/NSFileProviderItemProtocol/lastUsedDate) property in your File Provider extension’s working set.

The error parameter is used only for debugging purposes. The error is logged but not shown to the user.

---

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)