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

# predicateForObjects(withMetadataKey:)

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

## Declaration

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

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

## Discussion

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.

## 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:allowedValues:)](healthkit/hkquery/predicateforobjects(withmetadatakey:allowedvalues:).md)
- [predicateForObjects(withMetadataKey:operatorType:value:)](healthkit/hkquery/predicateforobjects(withmetadatakey:operatortype:value:).md)
- [predicateForObjectsWithNoCorrelation()](healthkit/hkquery/predicateforobjectswithnocorrelation().md)
