---
title: NSFilePresenter
framework: foundation
role: symbol
role_heading: Protocol
path: foundation/nsfilepresenter
---

# NSFilePresenter

The interface a file coordinator uses to inform an object presenting a file about changes to that file made elsewhere in the system.

## Declaration

```swift
protocol NSFilePresenter : NSObjectProtocol
```

## Mentioned in

Improving performance and stability when accessing the file system

## Overview

Overview Objects that allow the user to view or edit the content of files or directories should adopt the NSFilePresenter protocol. You use file presenters in conjunction with an NSFileCoordinator object to coordinate access to a file or directory among the objects of your application and between your application and other processes. When changes to an item occur, the system notifies objects that adopt this protocol and gives them a chance to respond appropriately. Use the methods of this protocol to respond to actions about to be taken on the presented file or directory. When another object or process uses a file coordinator to begin reading or writing a file or directory, the file coordinator notifies all presented objects interested in the item first. It notifies the presenter objects by invoking one of the methods defined by this protocol on that object. The actual invocation of that method occurs on the operation queue in the presentedItemOperationQueue property. Your file presenter must provide this queue. If your queue supports the concurrent execution of operations, the methods of your presenter object must be thread-safe and able to run in multiple queues simultaneously. You can use file presenters to coordinate access to a file or directory among your application’s objects. If another process uses a file coordinator for the same file or directory, your presenter objects are similarly notified whenever the other process makes its changes. Your presenter objects are not notified about changes made directly using low-level read and write calls to the file. Only changes that go through a file coordinator result in notifications. For information about how to use file presenters with a file coordinator object, see NSFileCoordinator. File Presenters and iOS If your app enters the background with an active file presenter, any other processes that perform a coordinated read or write on the presented file can deadlock. To prevent this situation, call the coordinator’s removeFilePresenter(_:) type method to remove the file presenter in the applicationDidEnterBackground(_:) method or in response to a didEnterBackgroundNotification notification. Call addFilePresenter(_:) to add the file presenter again in the applicationWillEnterForeground(_:) method or in response to a willEnterForegroundNotification notification. note: The UIDocument class automatically removes itself when your app goes to the background. It automatically adds itself again when your app returns to the foreground.

## Topics

### Accessing File Presenter Attributes

- [presentedItemURL](foundation/nsfilepresenter/presenteditemurl.md)
- [presentedItemOperationQueue](foundation/nsfilepresenter/presenteditemoperationqueue.md)
- [primaryPresentedItemURL](foundation/nsfilepresenter/primarypresenteditemurl.md)

### Relinquishing Managed Files

- [relinquishPresentedItem(toReader:)](foundation/nsfilepresenter/relinquishpresenteditem(toreader:).md)
- [relinquishPresentedItem(toWriter:)](foundation/nsfilepresenter/relinquishpresenteditem(towriter:).md)

### Handling Changes to Files

- [savePresentedItemChanges(completionHandler:)](foundation/nsfilepresenter/savepresenteditemchanges(completionhandler:).md)
- [accommodatePresentedItemDeletion(completionHandler:)](foundation/nsfilepresenter/accommodatepresenteditemdeletion(completionhandler:).md)
- [presentedItemDidMove(to:)](foundation/nsfilepresenter/presenteditemdidmove(to:).md)
- [presentedItemDidChange()](foundation/nsfilepresenter/presenteditemdidchange().md)

### Responding to Version Changes

- [presentedItemDidGain(_:)](foundation/nsfilepresenter/presenteditemdidgain(_:).md)
- [presentedItemDidLose(_:)](foundation/nsfilepresenter/presenteditemdidlose(_:).md)
- [presentedItemDidResolveConflict(_:)](foundation/nsfilepresenter/presenteditemdidresolveconflict(_:).md)
- [presentedSubitem(at:didGain:)](foundation/nsfilepresenter/presentedsubitem(at:didgain:).md)
- [presentedSubitem(at:didLose:)](foundation/nsfilepresenter/presentedsubitem(at:didlose:).md)
- [presentedSubitem(at:didResolve:)](foundation/nsfilepresenter/presentedsubitem(at:didresolve:).md)

### Handling Changes to a Presented Directory

- [accommodatePresentedSubitemDeletion(at:completionHandler:)](foundation/nsfilepresenter/accommodatepresentedsubitemdeletion(at:completionhandler:).md)
- [presentedSubitemDidAppear(at:)](foundation/nsfilepresenter/presentedsubitemdidappear(at:).md)
- [presentedSubitem(at:didMoveTo:)](foundation/nsfilepresenter/presentedsubitem(at:didmoveto:).md)
- [presentedSubitemDidChange(at:)](foundation/nsfilepresenter/presentedsubitemdidchange(at:).md)

### Ubiquity Change Notifications

- [observedPresentedItemUbiquityAttributes](foundation/nsfilepresenter/observedpresenteditemubiquityattributes.md)
- [presentedItemDidChangeUbiquityAttributes(_:)](foundation/nsfilepresenter/presenteditemdidchangeubiquityattributes(_:).md)

### Instance Methods

- [accommodatePresentedItemEviction(completionHandler:)](foundation/nsfilepresenter/accommodatepresenteditemeviction(completionhandler:).md)

## Relationships

### Inherits From

- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Coordinated file access

- [NSFileAccessIntent](foundation/nsfileaccessintent.md)
- [NSFileCoordinator](foundation/nsfilecoordinator.md)
