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

# predicateForObjects(withMetadataKey:)

Returns a predicate that matches any object whose metadata contains the provided key.

```
class func predicateForObjects(withMetadataKey key: String) -> NSPredicate
```

## Parameters

`key`

The metadata key to match. For a list of preset keys, see Metadata Keys. You may also search for custom keys.

## Return Value

A predicate that matches any object whose metadata contains the provided key.

## Discussion

Use this convenience method to create a predicate that finds all objects with a specific key stored in their metadata. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

```objc
NSPredicate *metadataKey =
    [HKQuery predicateForObjectsWithMetadataKey:HKMetadataKeyFoodType];
 
NSPredicate *explicitMetadataKey =
    [NSPredicate predicateWithFormat:@"%K.%K != nil",
     HKPredicateKeyPathMetadata,
     HKMetadataKeyFoodType];
```

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