Class

PHAssetChangeRequest

A request to create, delete, change metadata for, or edit the content of a Photos asset, for use in a photo library change block.

Overview

You use the PHAssetChangeRequest class to request changes for PHAsset objects. To make changes to assets in the Photos library, create a change request by using the appropriate class method for the change you want to perform.

  • Call one of the methods listed in Adding New Assets to create a new asset from an image or video file.

  • Call the deleteAssets(_:) method to delete existing assets.

  • Call the init(for:) method to modify an asset’s content or metadata.

A change request for creating or modifying an asset works like a mutable version of the asset object. Use the change request’s properties to request changes to the corresponding properties of the asset itself. For example, the following code uses the isFavorite property of a change request to mark an asset as a favorite:

- (void)toggleFavoriteForAsset:(PHAsset *)asset {
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        // Create a change request from the asset to be modified.
        PHAssetChangeRequest *request = [PHAssetChangeRequest changeRequestForAsset:asset];
        // Set a property of the request to change the asset itself.
        request.favorite = !asset.favorite;
 
    } completionHandler:^(BOOL success, NSError *error) {
        NSLog(@"Finished updating asset. %@", (success ? @"Success." : error));
    }];
}

After Photos runs the change block and calls your completion handler, the asset’s state reflects the changes that you requested in the block.

If you create or use a change request object outside a photo library change block, Photos raises an Objective-C exception. For details on change blocks, see PHPhotoLibrary.

Symbols

Adding New Assets

class func creationRequestForAsset(from: UIImage)

Creates a request for adding a new image asset to the Photos library.

class func creationRequestForAssetFromImage(atFileURL: URL)

Creates a request for adding a new image asset to the Photos library, using the image file at the specified URL.

class func creationRequestForAssetFromVideo(atFileURL: URL)

Creates a request for adding a new video asset to the Photos library, using the video file at the specified URL.

var placeholderForCreatedAsset: PHObjectPlaceholder?

A placeholder object for the asset that the change request creates.

Deleting Assets

class func deleteAssets(NSFastEnumeration)

Requests that the specified assets be deleted.

Modifying Assets

init(for: PHAsset)

Creates a request for modifying the specified asset.

var creationDate: Date?

The date and time at which the asset claims to have been originally created.

var location: CLLocation?

The location information saved with the asset.

var isFavorite: Bool

A Boolean value that indicates whether the asset is marked as one of the user’s favorites.

var isHidden: Bool

A Boolean value that indicates whether the asset is hidden in collections.

Editing Asset Content

var contentEditingOutput: PHContentEditingOutput?

The output of an asset content editing session.

func revertAssetContentToOriginal()

Request to revert any edits made to the asset’s content.

Relationships

Inherits From

Conforms To