<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.5.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSManagedObjectContext/count(for:)-93zbm",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSManagedObjectContext(im)countForFetchRequest:error:"
  },
  "title" : "count(for:)"
}
-->

# count(for:)

Returns the number of objects the specified request fetches when it executes.

```
func count(for request: NSFetchRequest<any NSFetchRequestResult>) throws -> Int
```

## Parameters

`request`

A fetch request that specifies the search criteria for the fetch.

## Return Value

The number of objects a given fetch request would have returned if it had been passed to [`fetch(_:)`](/documentation/CoreData/NSManagedObjectContext/fetch(_:)-38ys1), or `NSNotFound` if an error occurs.

## Discussion

---

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)