Type Method

predicateForSamplesWithStartDate:endDate:options:

Returns a predicate for samples whose start and end dates fall within the specified time interval.

Declaration

+ (NSPredicate *)predicateForSamplesWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate options:(HKQueryOptions)options;

Parameters

startDate

The start date for the target time interval.

endDate

The end date for the target time interval.

options

A constant that specifies how the sample’s start and end date are compared with the target time interval. For a list of possible values, see HKQueryOptions.

Return Value

A predicate for samples whose start and end dates fall within the specified time interval. This predicate works only with samples.

Discussion

Use this convenience method to create a predicate that compares a sample’s start and end dates with a specified time interval. The following sample uses both the convenience method and a predicate format string to create equivalent predicates.

NSPredicate *timeInterval =
[HKQuery predicateForSamplesWithStartDate:myStartDate
                                  endDate:myEndDate
                                  options:HKQueryOptionNone];
 
NSPredicate *explicitTimeInterval =
[NSPredicate predicateWithFormat:@"%K >= %@ AND %K < %@",
 HKPredicateKeyPathEndDate, myStartDate,
 HKPredicateKeyPathStartDate, myEndDate];

See Also

Creating Sample Predicates

HKQueryOptions

Constants that describe how a sample’s time period overlaps with the target time period.