title: Query HealthKit for HKCategoryTypeIdentifierSleepAnalysis
body: <p>I have built a method that imports a sleep sample but I can't get it to return the proper value for hours asleep.</p>
  
  <p>The method to query for sleep data looks like this:    </p>
  
  <pre><code>func updateHealthCategories() {
  
      let categoryType = HKObjectType.categoryTypeForIdentifier(HKCategoryTypeIdentifierSleepAnalysis)
  
      let start = NSDate(dateString:"2015-11-04")
      let end = NSDate(dateString:"2015-11-05")
  
      let categorySample = HKCategorySample(type: categoryType!,
          value: HKCategoryValueSleepAnalysis.Asleep.rawValue,
          startDate: start,
          endDate: end)
  
      self.hoursSleep = Double(categorySample.value)
  
      print(categorySample.value)
  }
  </code></pre>
  
  <p>The date is formatted like this:</p>
  
  <pre><code>extension NSDate
  {
      convenience
      init(dateString:String) {
          let dateStringFormatter = NSDateFormatter()
          dateStringFormatter.dateFormat = "yyyy-MM-dd"
          dateStringFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
          let d = dateStringFormatter.dateFromString(dateString)!
          self.init(timeInterval:0, sinceDate:d)
      }
  }
  </code></pre>
  
  <p>I'm calling data from November 4-5, which contains this data:</p>
  
  <p><a href="https://i.stack.imgur.com/mm4T2.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mm4T2.png" alt=""></a></p>
  
  <p><a href="https://i.stack.imgur.com/gMwLO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gMwLO.png" alt=""></a></p>
  
  <p>However, the <code>categorySample.value</code> returns <code>1</code> instead of <code>3</code>.</p>