<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.13.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "PhotoKit",
  "identifier" : "/documentation/Photos/PHFetchResult/countOfAssets(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Photos"
    ],
    "preciseIdentifier" : "c:objc(cs)PHFetchResult(im)countOfAssetsWithMediaType:"
  },
  "title" : "countOfAssets(with:)"
}
-->

# countOfAssets(with:)

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

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

## Parameters

`mediaType`

The type of assets to count, such as image or video. See [`PHAssetMediaType`](/documentation/Photos/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`](/documentation/Photos/PHAsset) objects in a fetch result. If a fetch result contains only [`PHAssetCollection`](/documentation/Photos/PHAssetCollection) or [`PHCollectionList`](/documentation/Photos/PHCollectionList) objects, the return value is `0`.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)