---
title: "predicateForCategorySamples(with:value:)"
framework: healthkit
role: symbol
role_heading: Type Method
path: "healthkit/hkquery/predicateforcategorysamples(with:value:)"
---

# predicateForCategorySamples(with:value:)

Returns a predicate that checks a category sample’s value.

## Declaration

```swift
class func predicateForCategorySamples(with operatorType: NSComparisonPredicate.Operator, value: Int) -> NSPredicate
```

## Parameters

- `operatorType`: The type of operation to perform when matching the category sample’s value against the target value. For a list of possible operators, see doc://com.apple.documentation/documentation/Foundation/NSComparisonPredicate/Operator/contains.
- `value`: The category sample’s target value. Use an enumeration value appropriate for the type of category samples you are working with. For example, a predicate for sleep analysis samples use values from the doc://com.apple.healthkit/documentation/HealthKit/HKCategoryValueSleepAnalysis enumeration.

## Return Value

Return Value A predicate that matches category samples based on the provided expression. This predicate works only with category samples.

## Discussion

Discussion Use this convenience method to create a predicate that checks a category sample’s value. The following listing uses both the convenience method and a predicate format string to create equivalent predicates.

## See Also

### Related Documentation

- [value](healthkit/hkcategorysample/value.md)
- [HKPredicateKeyPathCategoryValue](healthkit/hkpredicatekeypathcategoryvalue.md)

### Creating category sample predicates

- [HKCategoryValuePredicateProviding](healthkit/hkcategoryvaluepredicateproviding.md)
