Type Method

predicateForObjectsWithDeviceProperty:allowedValues:

Returns a predicate that matches all objects created by devices with the specified properties.

Declaration

+ (NSPredicate *)predicateForObjectsWithDeviceProperty:(NSString *)key allowedValues:(NSSet<NSString *> *)allowedValues;

Parameters

key

A string specifying the device’s property. For a list of valid keys, see Valid Device Property Keys.

allowedValues

A set of strings. These strings represent the target property values.

Return Value

A predicate that matches all objects created by a device whose specified property matches one of the allowed values.

Discussion

Use this convenience method to create a predicate that finds all the objects saved by matching devices. These predicates let you match multiple values for a single property. For example, you can create a single predicate that matches a number of different manufacturer values.

The following sample shows how to create a predicate that matches a list of device model names.

NSPredicate *fromDevices = [HKQuery predicateForObjectsWithDeviceProperty:HKDevicePropertyKeyModel allowedValues:modelNames];

Topics

Valid Device Property Keys

Use these keys to create predicates that match the specified device property.

HKDevicePropertyKeyName

The device’s name.

HKDevicePropertyKeyManufacturer

The device’s manufacturer.

HKDevicePropertyKeyModel

The device’s model.

HKDevicePropertyKeyHardwareVersion

The device’s hardware version.

HKDevicePropertyKeyFirmwareVersion

The device’s firmware version.

HKDevicePropertyKeySoftwareVersion

The device’s software version.

HKDevicePropertyKeyLocalIdentifier

A unique identifier for the device on the hardware running the app. For more information, see localIdentifier.

HKDevicePropertyKeyUDIDeviceIdentifier

The device’s UDI Device Identifier.

See Also

Creating Object Predicates

+ predicateForObjectWithUUID:

Returns a predicate that matches an object with the specified universally unique identifier (UUID).

+ predicateForObjectsWithUUIDs:

Returns a predicate that matches the objects with the specified universally unique identifiers (UUIDs).

+ predicateForObjectsFromSource:

Returns a predicate that matches all the objects that were created by the provided source.

+ predicateForObjectsFromSources:

Returns a predicate that matches all the objects that were created by any of the provided sources.

+ predicateForObjectsFromDevices:

Returns a predicate that matches all the objects that were created by any of the provided devices.

+ predicateForObjectsFromSourceRevisions:

Returns a predicate that matches all the objects that were created by any of the provided source revisions.

+ predicateForObjectsWithMetadataKey:

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

+ predicateForObjectsWithMetadataKey:allowedValues:

Returns a predicate that matches objects based on the provided metadata key and an array of target values.

+ predicateForObjectsWithMetadataKey:operatorType:value:

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

+ predicateForObjectsWithNoCorrelation

Returns a predicate that matches all objects that are not associated with a HealthKit correlation.