title: How to read heart rate from iOS HealthKit app using Swift?
body: <p>I'm using the following Swift code.</p>
  
  <pre><code>let sampleType : HKSampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
  let nowDate: NSDate = NSDate()
  var calendar: NSCalendar = NSCalendar.autoupdatingCurrentCalendar()
  
  let yearMonthDay: NSCalendarUnit = NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit
  
  var components: NSDateComponents = calendar.components(yearMonthDay , fromDate: nowDate)
  var beginOfDay : NSDate = calendar.dateFromComponents(components)!
  var predicate : NSPredicate = HKQuery.predicateForSamplesWithStartDate(beginOfDay, endDate: nowDate, options: HKQueryOptions.StrictStartDate)
  
  let squery: HKStatisticsQuery = HKStatisticsQuery(quantityType: sampleType, quantitySamplePredicate: predicate, options: HKStatisticsOptions.None) { (qurt, resul, errval) -&gt; Void in
  
      dispatch_async( dispatch_get_main_queue(), { () -&gt; Void in
          var quantity : HKQuantity = result.averageQuantity;
          var beats : double = quantity.doubleValueForUnit(HKUnit.heartBeatsPerMinuteUnit())
          // [quantity doubleValueForUnit:[HKUnit heartBeatsPerMinuteUnit]];
           self.txtfldHeartRate.text = "\(beats)"
      })
  
  }
  
  healthManager.healthKitStore.executeQuery(squery)
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <blockquote>
    <p>Cannot find an initializer for type 'HKStatisticsQuery' that accepts an argument list of type '(quantityType: HKSampleType, quantitySamplePredicate: NSPredicate, options: HKStatisticsOptions, (_, _, _) -> Void)'</p>
  </blockquote>
  
  <p>Please advise me how to resolve this issue.</p>