---
title: "expression(forFetch:context:countOnly:)"
framework: coredata
role: symbol
role_heading: Type Method
path: "coredata/nsfetchrequestexpression/expression(forfetch:context:countonly:)"
---

# expression(forFetch:context:countOnly:)

Returns an expression which will evaluate to the result of executing a fetch request on a context.

## Declaration

```swift
class func expression(forFetch fetch: NSExpression, context: NSExpression, countOnly countFlag: Bool) -> NSExpression
```

## Parameters

- `fetch`: An expression that evaluates to an instance of NSFetchRequest.
- `context`: An expression that evaluates to an instance of NSManagedObjectContext.
- `countFlag`: If doc://com.apple.documentation/documentation/Swift/true, when the new expression is evaluated the managed object context (from context) will perform doc://com.apple.coredata/documentation/CoreData/NSManagedObjectContext/count(for:)-93zbm with the fetch request (from fetch). If doc://com.apple.documentation/documentation/Swift/false, when the new expression is evaluated the managed object context will perform doc://com.apple.coredata/documentation/CoreData/NSManagedObjectContext/fetch(_:)-38ys1 with the fetch request.

## Return Value

Return Value An expression which will evaluate to the result of executing a fetch request (from fetch) on a managed object context (from context).

## See Also

### Related Documentation

- [Predicate Programming Guide](apple-archive/documentation/Cocoa/Conceptual/Predicates/AdditionalChapters/Introduction.html.md)
- [Core Data Programming Guide](apple-archive/documentation/Cocoa/Conceptual/CoreData.md)
