---
title: "setLastUsedDate(_:forItemIdentifier:completionHandler:)"
framework: fileprovider
role: symbol
role_heading: Instance Method
path: "fileprovider/nsfileproviderextension/setlastuseddate(_:foritemidentifier:completionhandler:)"
---

# setLastUsedDate(_:forItemIdentifier:completionHandler:)

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

## Declaration

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

```swift
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:

## Discussion

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: func setLastUsedDate(_ lastUsedDate: Date?, forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem For information about concurrency and asynchronous code in Swift, see 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 property with the value of the lastUsedDate parameter Always include Items with a non-nil 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.

## See Also

### Handling actions

- [Providing support for user-driven actions](fileprovider/providing-support-for-user-driven-actions.md)
- [createDirectory(withName:inParentItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/createdirectory(withname:inparentitemidentifier:completionhandler:).md)
- [deleteItem(withIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/deleteitem(withidentifier:completionhandler:).md)
- [importDocument(at:toParentItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/importdocument(at:toparentitemidentifier:completionhandler:).md)
- [renameItem(withIdentifier:toName:completionHandler:)](fileprovider/nsfileproviderextension/renameitem(withidentifier:toname:completionhandler:).md)
- [reparentItem(withIdentifier:toParentItemWithIdentifier:newName:completionHandler:)](fileprovider/nsfileproviderextension/reparentitem(withidentifier:toparentitemwithidentifier:newname:completionhandler:).md)
- [setFavoriteRank(_:forItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/setfavoriterank(_:foritemidentifier:completionhandler:).md)
- [setTagData(_:forItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/settagdata(_:foritemidentifier:completionhandler:).md)
- [trashItem(withIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/trashitem(withidentifier:completionhandler:).md)
- [untrashItem(withIdentifier:toParentItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/untrashitem(withidentifier:toparentitemidentifier:completionhandler:).md)
