<!--
{
  "availability" : [
    "iOS: 15.4.0 -",
    "iPadOS: 15.4.0 -",
    "macCatalyst: 15.4.0 -",
    "macOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 8.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKSamplePredicate/categorySample(type:predicate:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "s:9HealthKit17HKSamplePredicateV14categorySample4type9predicateACySo010HKCategoryF0CGSo0I4TypeC_So11NSPredicateCSgtFZ"
  },
  "title" : "categorySample(type:predicate:)"
}
-->

# categorySample(type:predicate:)

Returns a sample predicate that matches category samples.

```
static func categorySample(type categoryType: HKCategoryType, predicate: NSPredicate? = nil) -> HKSamplePredicate<HKCategorySample>
```

## Parameters

`categoryType`

A type that identifies samples that contain a value from a small set of possible values.

`predicate`

An optional predicate that further restricts the results that the query returns.

## Discussion

Use this method to create an [`HKSamplePredicate`](/documentation/HealthKit/HKSamplePredicate) instance that you can use to query for [`HKCategorySample`](/documentation/HealthKit/HKCategorySample) objects.

---

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)