Initializer

init(for:assets:)

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

Declaration

convenience init?(for assetCollection: PHAssetCollection, assets: PHFetchResult<PHAsset>)

Parameters

assetCollection

The asset collection to be modified.

assets

A fetch result listing the assets in the collection.

Return Value

An asset collection change request.

Discussion

After you create a change request within a photo library change block, you propose changes to the collection’s title or list of member assets with the properties and instance methods of the change request. After Photos runs your change block, the asset collection reflects your changes. For details on change blocks, see PHPhotoLibrary.

Use this method when you need to insert, remove, or rearrange assets at specified indexes in the asset collection’s list of member assets. By passing in a fetch result reflecting what your app sees as the current state of the collection’s membership, the Photos framework can ensure that the indexes you specify are valid even if the collection has changed since you last fetched it. If you don’t need to work with indexes in the list of member assets, you can use the init(for:) method instead.

See Also

Modifying Asset Collections

init?(for: PHAssetCollection)

Creates a request for modifying the specified asset collection.

var title: String

The displayed name of the asset collection.

func addAssets(NSFastEnumeration)

Add the specified assets to the asset collection.

func insertAssets(NSFastEnumeration, at: IndexSet)

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

func removeAssets(NSFastEnumeration)

Removes the specified assets from the asset collection.

func removeAssets(at: IndexSet)

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

func replaceAssets(at: IndexSet, withAssets: NSFastEnumeration)

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

func moveAssets(at: IndexSet, to: Int)

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