Type Method

predicateForActivitySummariesBetweenStartDateComponents:endDateComponents:

Returns a predicate for matching all the activity summaries that fall between the days identified by the start and end date components.

Declaration

+ (NSPredicate *)predicateForActivitySummariesBetweenStartDateComponents:(NSDateComponents *)startDateComponents endDateComponents:(NSDateComponents *)endDateComponents;

Parameters

startDateComponents

Date components that uniquely identify the start day as perceived by the user. This day may be longer or shorter than 24 hours (for example, if the user traveled across time zones).

The date components must have a valid calendar property.

endDateComponents

Date components that uniquely identify the end day as perceived by the user. This day may be longer or shorter than 24 hours (for example, if the user traveled across time zones).

The date components must have a valid calendar property.

Return Value

A predicate for matching activity summaries spanning a range of days.

Discussion

Use this convenience method to create a predicate that matches activity summaries that fall between the specified days. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

NSPredicate *forDay =
[HKQuery HKQuery.predicateForActivitySummariesBetweenStartDateComponents: startDateComponents endDateComponents:endDateComponents];
 
NSPredicate *explicitforDay =
[NSPredicate predicateWithFormat:@"%K >= %@ AND %K <= %@",
 HKPredicateKeyPathDateComponents, startDateComponents,
 HKPredicateKeyPathDateComponents, endDateComponents];

See Also

Creating Activity Summary Predicates

+ predicateForActivitySummaryWithDateComponents:

Returns a predicate that matches the activity summary for the specified day.