---
title: "predicateForObjects(withMetadataKey:operatorType:value:)"
framework: healthkit
role: symbol
role_heading: Type Method
path: "healthkit/hkquery/predicateforobjects(withmetadatakey:operatortype:value:)"
---

# predicateForObjects(withMetadataKey:operatorType:value:)

Returns a predicate that matches objects based on the provided metadata key, value, and operator.

## Declaration

```swift
class func predicateForObjects(withMetadataKey key: String, operatorType: NSComparisonPredicate.Operator, value: Any) -> NSPredicate
```

## Parameters

- `key`: The metadata key for the value to be matched. For a list of preset keys, see doc://com.apple.healthkit/documentation/HealthKit/metadata-keys. You may also search using custom keys.
- `operatorType`: Defines the relationship used to match the metadata’s value with the provided value.
- `value`: The target value. These values must be doc://com.apple.documentation/documentation/Foundation/NSString, doc://com.apple.documentation/documentation/Foundation/NSNumber, or doc://com.apple.documentation/documentation/Foundation/NSDate instances.

## Return Value

Return Value A predicate that matches objects based on the specified metadata key, operator, and value.

## Discussion

Discussion Use this convenience method to create a predicate that matches objects based on their metadata, an operator, and a target value. When this predicate is evaluated, it gets the metadata’s value for the provided key. Then the predicate compares that value with the target value using the provided operator. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

## See Also

### Related Documentation

- [HKPredicateKeyPathMetadata](healthkit/hkpredicatekeypathmetadata.md)
- [metadata](healthkit/hkobject/metadata.md)

### Creating object predicates

- [predicateForObject(with:)](healthkit/hkquery/predicateforobject(with:).md)
- [predicateForObjects(with:)](healthkit/hkquery/predicateforobjects(with:).md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-7j3p2.md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-89b4t.md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-9h87f.md)
- [predicateForObjects(withDeviceProperty:allowedValues:)](healthkit/hkquery/predicateforobjects(withdeviceproperty:allowedvalues:).md)
- [predicateForObjects(from:)](healthkit/hkquery/predicateforobjects(from:)-1ar4g.md)
- [predicateForObjects(withMetadataKey:)](healthkit/hkquery/predicateforobjects(withmetadatakey:).md)
- [predicateForObjects(withMetadataKey:allowedValues:)](healthkit/hkquery/predicateforobjects(withmetadatakey:allowedvalues:).md)
- [predicateForObjectsWithNoCorrelation()](healthkit/hkquery/predicateforobjectswithnocorrelation().md)
