<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PhotoKit",
  "identifier" : "/documentation/Photos/PHPhotoLibraryChangeObserver",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Photos"
    ],
    "preciseIdentifier" : "c:objc(pl)PHPhotoLibraryChangeObserver"
  },
  "title" : "PHPhotoLibraryChangeObserver"
}
-->

# PHPhotoLibraryChangeObserver

A protocol to adopt to have the system notify your app of changes to the photo library.

```
protocol PHPhotoLibraryChangeObserver : NSObjectProtocol
```

## Overview

The [`PHPhotoLibraryChangeObserver`](/documentation/Photos/PHPhotoLibraryChangeObserver) protocol notifies you of changes that occur in the photo library, regardless of whether those changes are made by your app, by a user in the Photos app, or by another app that uses the Photos framework. To receive change messages, register your observer with the [`register(_:)`](/documentation/Photos/PHPhotoLibrary/register(_:)-6y3b9) method. For any assets or collections that you fetch, Photos sends change messages whenever those assets or collections change. Use this protocol to track changes across multiple parts of your app or respond to changes made in another app or extension.

### Handling Changes: An Example

The example code below shows how you might implement this protocol in a view controller that uses a <doc://com.apple.documentation/documentation/UIKit/UICollectionView> interface to display the contents of an album. The view controller keeps a reference to the [`PHAssetCollection`](/documentation/Photos/PHAssetCollection) object representing the displayed album and the [`PHFetchResult`](/documentation/Photos/PHFetchResult) object (returned by the [`fetchAssets(in:options:)`](/documentation/Photos/PHAsset/fetchAssets(in:options:)) method) listing the album’s contents. Then, in its [`photoLibraryDidChange(_:)`](/documentation/Photos/PHPhotoLibraryChangeObserver/photoLibraryDidChange(_:)) method, the view controller checks for differences between the objects it fetched and the new state of the photo library, and updates its collection view accordingly.

```swift
func photoLibraryDidChange(_ changeInstance: PHChange) {
    guard let collectionView = self.collectionView else { return }
    // Change notifications may be made on a background queue.
    // Re-dispatch to the main queue to update the UI.
    DispatchQueue.main.sync {
        // Check for changes to the displayed album itself
        // (its existence and metadata, not its member assets).
        if let albumChanges = changeInstance.changeDetails(for: assetCollection) {
            // Fetch the new album and update the UI accordingly.
            assetCollection = albumChanges.objectAfterChanges! as! PHAssetCollection
            navigationController?.navigationItem.title = assetCollection.localizedTitle
        }
        // Check for changes to the list of assets (insertions, deletions, moves, or updates).
        if let changes = changeInstance.changeDetails(for: fetchResult) {
            // Keep the new fetch result for future use.
            fetchResult = changes.fetchResultAfterChanges
            if changes.hasIncrementalChanges {
                // If there are incremental diffs, animate them in the collection view.
                collectionView.performBatchUpdates({
                    // For indexes to make sense, updates must be in this order:
                    // delete, insert, reload, move.
                    if let removed = changes.removedIndexes where removed.count > 0 {
                        collectionView.deleteItems(at: removed.map { IndexPath(item: $0, section:0) })
                    }
                    if let inserted = changes.insertedIndexes where inserted.count > 0 {
                        collectionView.insertItems(at: inserted.map { IndexPath(item: $0, section:0) })
                    }
                    if let changed = changes.changedIndexes where changed.count > 0 {
                        collectionView.reloadItems(at: changed.map { IndexPath(item: $0, section:0) })
                    }
                    changes.enumerateMoves { fromIndex, toIndex in
                        collectionView.moveItem(at: IndexPath(item: fromIndex, section: 0),
                                                to: IndexPath(item: toIndex, section: 0))
                    }
                })
            } else {
                // Reload the collection view if incremental diffs aren't available.
                collectionView.reloadData()
            }
        }
    }
}
```

## Topics

### Observing Photo Library Changes

[`photoLibraryDidChange(_:)`](/documentation/Photos/PHPhotoLibraryChangeObserver/photoLibraryDidChange(_:))

Tells your observer that a set of changes has occurred in the Photos library.



---

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)