---
title: "countOfAssets(with:)"
framework: photos
role: symbol
role_heading: Instance Method
path: "photos/phfetchresult/countofassets(with:)"
---

# countOfAssets(with:)

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

## Declaration

```swift
func countOfAssets(with mediaType: PHAssetMediaType) -> Int
```

## Parameters

- `mediaType`: The type of assets to count, such as image or video. See doc://com.apple.photokit/documentation/Photos/PHAssetMediaType.

## Return Value

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

## Discussion

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

- [contains(_:)](photos/phfetchresult/contains(_:).md)
- [count](photos/phfetchresult/count.md)
- [firstObject](photos/phfetchresult/firstobject.md)
- [lastObject](photos/phfetchresult/lastobject.md)
- [object(at:)](photos/phfetchresult/object(at:).md)
- [subscript(_:)](photos/phfetchresult/subscript(_:).md)
- [objects(at:)](photos/phfetchresult/objects(at:).md)
