I have an array of HKSampleType for steps taken. I am trying to pickup one HKQuantitySample (steps taken) based on matching date. Turns out there is no date property. My code crashes saying there is no key called date, which is true.
How do I pickup one object from the array that is for the date I want.
Here is my code...
NSArray *stepsArray = caloriesHandle.stepsTakenSampleArray;
NSPredicate *stepsPredicate = [NSPredicate predicateWithFormat:@"date=%@",historyDate];
NSArray *stepsPredicateResultsArray = [stepsArray filteredArrayUsingPredicate:stepsPredicate];
when i change the format to @"endDate=%@",historyDate it doesn't return any results.
Could it be because of the time inside the historyDate? if yes, what is the solution.
If you are comparing against > previous day and < next day, it's perfectly correct to show the total of today and previous day. Because it includes the times. if your previous day is set to 0:00 and you check against > 0:00 then 0:01 already qualifies. Thats still data for yesterday, but thats what you asked for in your predicate.
Please see my previous answer again. You first need to start of the day for today. Then startDate needs to be bigger or equal to that and smaller to start of next day. So if you want everything for today, you need:
today at 00:00 <= startDate < tomorrow at 00:00