<!--
{
  "availability" : [
    "iOS: 8.0.0 - 27.0.0",
    "iPadOS: 8.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: -",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuery/predicateForCategorySamples(with:value:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuery(cm)predicateForCategorySamplesWithOperatorType:value:"
  },
  "title" : "predicateForCategorySamples(with:value:)"
}
-->

# predicateForCategorySamples(with:value:)

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

```
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 [`HKCategoryValueSleepAnalysis`](/documentation/HealthKit/HKCategoryValueSleepAnalysis) enumeration.

## Return Value

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

## 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.

```objc
NSPredicate *asleep =
    [HKQuery
     predicateForCategorySamplesWithOperatorType:NSEqualToPredicateOperatorType
     value:HKCategoryValueSleepAnalysisAsleep];
 
NSPredicate *explicitAsleep =
    [NSPredicate predicateWithFormat:@"%K == %d",
     HKPredicateKeyPathCategoryValue,
     HKCategoryValueSleepAnalysisAsleep];
```

## See Also

[`value`](/documentation/HealthKit/HKCategorySample/value)

The category value for this sample.

[`HKPredicateKeyPathCategoryValue`](/documentation/HealthKit/HKPredicateKeyPathCategoryValue)

The key path for accessing the category sample’s value.



---

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)