Class

PHFetchResult

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

Declaration

@interface PHFetchResult<__covariant ObjectType> : NSObject

Overview

When you use class methods on the PHAsset, PHCollection, PHAssetCollection, and PHCollectionList classes to retrieve objects, Photos provides the resulting objects in a fetch result. You access the contents of a fetch result with the same methods and conventions used by the NSArray class. Unlike an NSArray object, however, a PHFetchResult object dynamically loads its contents from the Photos library as needed, providing optimal performance even when handling a large number of results.

A fetch result provides thread-safe access to its contents. After a fetch, the fetch result’s count value is constant, and all objects in the fetch result keep the same localIdentifier value. (To get updated content for a fetch, register a change observer with the shared PHPhotoLibrary object.)

A fetch result caches its contents, keeping a batch of objects around the most recently accessed index. Because objects outside of the batch are no longer cached, accessing these objects results in refetching those objects. This process can result in changes to values previously read from those objects.

Topics

Querying a Fetch Result

- containsObject:

Returns whether the specified object is present in the fetch result.

count

The number of objects in the fetch result.

- countOfAssetsWithMediaType:

Returns the number of assets in the fetch result of a specified type.

firstObject

The first object in the fetch result.

lastObject

The last object in the fetch result.

- objectAtIndex:

Returns the object located at the specified index.

- objectAtIndexedSubscript:

Returns the object located at the specified index.

- objectsAtIndexes:

Returns an array containing the objects in the fetch result at the indexes in the specified index set.

Finding Objects in a Fetch Result

- indexOfObject:

Returns the lowest index whose corresponding object in the fetch result is equal to the specified object.

- indexOfObject:inRange:

Returns the lowest index within the specified range whose corresponding object in the fetch result is equal to the specified object.

Performing Operations with Objects in a Fetch Result

- enumerateObjectsAtIndexes:options:usingBlock:

Executes the specified block using the objects in the fetch result at the specified indexes.

- enumerateObjectsUsingBlock:

Executes the specified block using each object in the fetch result, starting with the first object and continuing in order to the last object.

- enumerateObjectsWithOptions:usingBlock:

Executes the specified block using each object in the fetch result.

Relationships

Inherits From

See Also

Asset Retrieval

Fetching Objects and Requesting Changes

Get assets, asset collections, and collection lists matching a specified query.

PHAsset

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

PHAssetCollection

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

PHCollection

The abstract superclass for Photos asset collections and collection lists.

PHCollectionList

A group containing Photos asset collections, such as Moments, Years, or folders of user-created albums.

PHObject

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

PHFetchOptions

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