---
title: "predicateForQuantitySamples(with:quantity:)"
framework: healthkit
role: symbol
role_heading: Type Method
path: "healthkit/hkquery/predicateforquantitysamples(with:quantity:)"
---

# predicateForQuantitySamples(with:quantity:)

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

## Declaration

```swift
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

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

## Discussion

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.

## See Also

### Related Documentation

- [HKPredicateKeyPathQuantity](healthkit/hkpredicatekeypathquantity.md)
- [quantity](healthkit/hkquantitysample/quantity.md)
