<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "HealthKit",
  "identifier" : "/documentation/HealthKit/HKQuery/predicateForQuantitySamples(with:quantity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "HealthKit"
    ],
    "preciseIdentifier" : "c:objc(cs)HKQuery(cm)predicateForQuantitySamplesWithOperatorType:quantity:"
  },
  "title" : "predicateForQuantitySamples(with:quantity:)"
}
-->

# predicateForQuantitySamples(with:quantity:)

Returns a predicate that matches samples based on the target quantity.

```
class func predicateForQuantitySamples(with operatorType: NSComparisonPredicate.Operator, quantity: HKQuantity) -> NSPredicate
```

## Parameters

`operatorType`

The operator type to use when comparing the sample’s quantity to the target quantity.

`quantity`

The target quantity object.

## Return Value

A predicate that matches samples based on the target quantity. This predicate works only on quantity samples.

## Discussion

Use this convenience method to create a predicate that matches against a sample’s quantity. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

```objc
HKQuantity *targetWeight =
[HKQuantity quantityWithUnit:[HKUnit poundUnit]
                 doubleValue:150.0];
 
NSPredicate *underTargetWeight =
[HKQuery predicateForQuantitySamplesWithOperatorType:
    NSLessThanOrEqualToPredicateOperatorType
    quantity:targetWeight];
 
NSPredicate *explicitUnderTargetWeight =
[NSPredicate predicateWithFormat:@"%K <= %@",
 HKPredicateKeyPathQuantity,
 targetWeight];
```

## See Also

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

The key path for accessing the sample’s quantity.

[`quantity`](/documentation/HealthKit/HKQuantitySample/quantity)

The quantity for this sample.



---

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)