Type Method

predicateForSamples(withStart:end:options:)

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

Declaration

class func predicateForSamples(withStart startDate: Date?, end endDate: Date?, options: HKQueryOptions = []) -> NSPredicate

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.

let timeInterval =
    HKQuery.predicateForSamplesWithStartDate(myStartDate,
                                             endDate: myEndDate, options: .None)
 
let explicitTimeInterval = NSPredicate(format: "%K >= %@ AND %K < %@",
                                       HKPredicateKeyPathEndDate, myStartDate,
                                       HKPredicateKeyPathStartDate, myEndDate)

See Also

Creating Sample Predicates

struct HKQueryOptions

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