Contents

countOfAssets(with:)

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

Declaration

func countOfAssets(with mediaType: PHAssetMediaType) -> Int

Parameters

  • mediaType:

    The type of assets to count, such as image or video. See Phassetmediatype.

Return Value

The number of assets in the fetch result of the specified type.

Discussion

The first time you call this method, Photos enumerates the contents of the fetch result to count those of the specified type, then caches the result. Subsequent calls with the same mediaType parameter return the cached value.

This method counts only the PHAsset objects in a fetch result. If a fetch result contains only PHAssetCollection or PHCollectionList objects, the return value is 0.

See Also

Querying a Fetch Result