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

# predicateForObjects(withMetadataKey:operatorType:value:)

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

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

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

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

```objc
NSPredicate *metadataOperator =
    [HKQuery predicateForObjectsWithMetadataKey:AccuracyCustomMetadataKey
                                   operatorType:NSGreaterThanPredicateOperatorType
                                          value:@75.0];
 
NSPredicate *explicitMetadataOperator =
    [NSPredicate predicateWithFormat:@"%K.%K > %d",
     HKPredicateKeyPathMetadata,
     AccuracyCustomMetadataKey,
     @75.0];
```

## See Also

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

The key path for accessing the object’s metadata dictionary inside a predicate format string.

[`metadata`](/documentation/HealthKit/HKObject/metadata)

The metadata for this HealthKit object.



---

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)