Class

PHAsset​Collection​Change​Request

A request to create, delete, or modify a Photos asset collection, for use in a photo library change block.

Overview

You use the PHAsset​Collection​Change​Request class to request changes for PHAsset​Collection objects. To make changes to asset collections (such as user-created albums) in the Photos library, create a change request using the appropriate class method for the change you want to perform.

Before creating a change request, use the can​Perform(_:​) method to verify that the collection allows the edit operation you’re requesting. If you attempt to perform an unsupported edit operation, Photos throws an exception.

A change request for creating or modifying an asset collection works like a mutable version of the asset collection object. Use the change request’s properties and instance methods to request changes to the asset collection itself. For example, the following code removes an asset from an album:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetCollectionChangeRequest *request = [PHAssetCollectionChangeRequest
        changeRequestForAssetCollection:self.myAlbum
                                 assets:self.albumAssetsFetchResult];
    [request removeAssets:@[asset]];
 
} completionHandler:^(BOOL success, NSError *error) {
    NSLog(@"Finished removing asset from the album. %@", (success ? @"Success" : error));
}];

After Photos runs the change block and calls your completion handler, the asset collection’s state reflects the changes 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 PHPhoto​Library.

Symbols

Adding New Asset Collections

class func creation​Request​For​Asset​Collection(with​Title:​ String)

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

var placeholder​For​Created​Asset​Collection:​ PHObject​Placeholder

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

Deleting Asset Collections

class func delete​Asset​Collections(NSFast​Enumeration)

Requests that the specified asset collections be deleted.

Modifying Asset Collections

init?(for:​ PHAsset​Collection)

Creates a request for modifying the specified asset collection.

init?(for:​ PHAsset​Collection, assets:​ PHFetch​Result<PHAsset>)

Creates a request for modifying the specified asset collection, with a fetch result for tracking changes.

var title:​ String

The displayed name of the asset collection.

func add​Assets(NSFast​Enumeration)

Add the specified assets to the asset collection.

func insert​Assets(NSFast​Enumeration, at:​ Index​Set)

Inserts the specified assets into the collection at the specified indexes.

func remove​Assets(NSFast​Enumeration)

Removes the specified assets from the asset collection.

func remove​Assets(at:​ Index​Set)

Removes the assets at the specified indexes from the asset collection.

func replace​Assets(at:​ Index​Set, with​Assets:​ NSFast​Enumeration)

Replaces the assets at the specified indexes in the asset collection with the specified assets.

func move​Assets(at:​ Index​Set, to:​ Int)

Moves the assets at the specified indexes in the asset collection to a new index.

Relationships

Inherits From