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.

Overview

Using class methods on the PHAsset, PHCollection, PHAssetCollection, and PHCollectionList classes to fetch assets or collections produces a PHFetchResult object containing the requested objects. The options you specify control which objects the fetch result includes, how those objects are arranged in the fetch result, and how Photos should notify your app of changes to the fetch result.

Photos supports only a restricted set of keys for the predicate and sortDescriptors properties. The set of available keys depends on which class you’re using to fetch assets or collections—see Table 1 for the list of keys supported by each class.

Table 1

Supported predicate and sort descriptor keys

Class for Fetch Method

Supported Keys

PHAsset

SELF, localIdentifier, creationDate, modificationDate, mediaType, mediaSubtypes, duration, pixelWidth, pixelHeight, isFavorite (or isFavorite), isHidden (or isHidden), burstIdentifier

PHAssetCollection

SELF, localIdentifier, localizedTitle (or title), startDate, endDate, estimatedAssetCount

PHCollectionList

SELF, localIdentifier, localizedTitle (or title), startDate, endDate

PHCollection (can fetch a mix of PHCollectionList and PHAssetCollection objects)

SELF, localIdentifier, localizedTitle (or title), startDate, endDate

Topics

Sorting and Filtering Fetch Results

var predicate: NSPredicate?

A predicate that specifies which properties to select results by and that also specifies any constraints on selection.

var sortDescriptors: [NSSortDescriptor]?

A list of sort descriptors, specifying an order for the fetched objects.

Subscribing to Changes

var wantsIncrementalChangeDetails: Bool

A Boolean value that determines whether your app receives detailed change information for the objects in the fetch result.

Limiting Fetch Results

var fetchLimit: Int

The maximum number of objects to include in the fetch result.

var includeAllBurstAssets: Bool

A Boolean value that determines whether the fetch result includes all assets from burst photo sequences.

var includeHiddenAssets: Bool

A Boolean value that determines whether the fetch result includes assets marked as hidden.

var includeAssetSourceTypes: PHAssetSourceType

The set of source types for which to include assets in the 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 PHAssetCollection

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

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.

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