Instance Method

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

func contains(ObjectType) -> Bool

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

var count: Int

The number of objects in the fetch result.

var firstObject: ObjectType?

The first object in the fetch result.

var lastObject: ObjectType?

The last object in the fetch result.

func object(at: Int) -> ObjectType

Returns the object located at the specified index.

subscript(Int) -> ObjectType

Returns the object located at the specified index.

func objects(at: IndexSet) -> [ObjectType]

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