title: HealthKit Swift getting today's steps
body: <p>I am making a swift iOS app that integrates with a user's step count as reported by the Health app. I can easily find the user's step count in the last hour, using this as my predicate:</p>
  
  <pre><code>let anHourBeforeNow: NSDate = NSDate().dateByAddingTimeInterval(-60 * 60)
  let predicate = HKQuery.predicateForSamplesWithStartDate(anHourBeforeNow, endDate: NSDate(), options: .None)
  </code></pre>
  
  <p>And I have the rest down, so I can successfully access the user's step count for the last hour. <strong>But how can I access the user's step data since the day began, like the Health app displays in the steps section?</strong></p>
  
  <p>I am trying to do something like this:</p>
  
  <pre><code>let date = NSDate()
  let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
  let newDate = cal.startOfDayForDate(date)
  let predicate = HKQuery.predicateForSamplesWithStartDate(newDate, endDate: NSDate(), options: .None)
  </code></pre>
  
  <p>but this code does not adjust for time zone (so it gives me the beginning of the day in UTC, not the beginning of the day where the user is) and I am also getting highly inflated step counts (for reasons unknown).</p>
  
  <p><strong>So how can I get the user's step count for the current day, with the same number of steps as reported in Health, like pictured here:</strong><a href="https://i.stack.imgur.com/NMOEA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NMOEA.png" alt="enter image description here"></a></p>