Contents

PHPhotoLibraryChangeObserver

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

Declaration

protocol PHPhotoLibraryChangeObserver : NSObjectProtocol

Mentioned in

Overview

The 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(_:) 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 UICollectionView interface to display the contents of an album. The view controller keeps a reference to the PHAssetCollection object representing the displayed album and the PHFetchResult object (returned by the fetchAssets(in:options:) method) listing the album’s contents. Then, in its 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.

Topics

Observing Photo Library Changes

See Also

Observing Library Changes