Class

PHAssetCollection

A representation of a Photos asset grouping, such as a moment, user-created album, or smart album.

Overview

In the Photos framework, collection objects (including asset collections) do not directly reference their member objects, and there are no other objects that directly reference collection objects. To retrieve the members of an asset collection, fetch them with a PHAsset class method such as fetchAssets(in:options:). To find asset collections, use one of the methods listed in Fetching Asset Collections.

Like assets and collection lists, asset collections are immutable. To create, rename, or delete asset collections, or to add, remove, or rearrange members in an asset collection, create a PHAssetCollectionChangeRequest object within a photo library change block. For details on using change requests and change blocks to update the photo library, see PHPhotoLibrary.

Symbols

Fetching Asset Collections

class func fetchAssetCollections(withLocalIdentifiers: [String], options: PHFetchOptions?)

Retrieves asset collections with the specified unique identifiers.

class func fetchAssetCollectionsContaining(PHAsset, with: PHAssetCollectionType, options: PHFetchOptions?)

Retrieves asset collections of the specified type containing the specified asset.

class func fetchAssetCollections(withALAssetGroupURLs: [URL], options: PHFetchOptions?)

Retrieves asset collections using URLs provided by the Assets Library framework.

class func fetchMoments(inMomentList: PHCollectionList, options: PHFetchOptions?)

Retrieves asset collections in the specified moment list collection.

class func fetchMoments(with: PHFetchOptions?)

Retrieves asset collections corresponding to moments seen in the Photos app.

Reading Asset Collection Metadata

var assetCollectionType: PHAssetCollectionType

The type of the asset collection, such as an album or a moment.

var assetCollectionSubtype: PHAssetCollectionSubtype

The subtype of the asset collection.

var estimatedAssetCount: Int

The estimated number of assets in the asset collection.

var startDate: Date?

The earliest creation date among all assets in the asset collection.

var endDate: Date?

The latest creation date among all assets in the asset collection.

var approximateLocation: CLLocation?

A location representing those of all assets in the collection.

var localizedLocationNames: [String]

The names of locations grouped by the collection (an array of NSString objects).

Creating Temporary Asset Collections

class func transientAssetCollection(with: [PHAsset], title: String?)

Creates a temporary asset collection containing the specified assets.

class func transientAssetCollection(withAssetFetchResult: PHFetchResult<PHAsset>, title: String?)

Creates a temporary asset collection containing the assets from the specified fetch result.

Constants

PHAssetCollectionType

Major distinctions between kinds of asset collections, used by the assetCollectionType property and the fetchAssetCollectionsContaining(_:with:options:) and fetchAssetCollections(with:subtype:options:) methods.

PHAssetCollectionSubtype

Minor distinctions between kinds of asset collections, used by the assetCollectionSubtype property and the fetchAssetCollections(with:subtype:options:) method.

Relationships

Inherits From