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.

Topics

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.

enum PHAssetCollectionType

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

var assetCollectionSubtype: PHAssetCollectionSubtype

The subtype of the asset collection.

enum PHAssetCollectionSubtype

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

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.

Relationships

Inherits From

See Also

Retrieving and Examining Assets

class PHAsset

A representation of an image, video or Live Photo in the Photos library.

class PHCollectionList

A representation of a group containing Photos asset collections, such as a moments year or a folder of user-created albums.

class PHCollection

The abstract superclass for Photos asset collections and collection lists.

class PHObject

The abstract superclass for Photos model objects (assets and collections).

class PHFetchResult

An ordered list of assets or collections returned from a Photos fetch method.

class PHFetchOptions

A set of options that affect the filtering, sorting, and management of results that Photos returns when you fetch asset or collection objects.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software