我无法使用类型的参数列表从日期调用启动计步器更新。
它在Swift 1.2中运行,但是现在我迁移到Swift 2后,它出现了错误。
if(CMPedometer.isStepCountingAvailable()){
self.manager.deviceMotionUpdateInterval = 0.1
self.coremotion.startPedometerUpdatesFromDate(NSDate()) {
(data: CMPedometerData!, error) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil){
println(data.numberOfSteps)
self.pedoLabel.text = "\(data.numberOfSteps)"
self.label.text = ("Great you have \(data.numberOfSteps) steps")
}
})
}
}
答案 0 :(得分:3)
使用可选:(数据:CMPedometerData?,错误)
if(CMPedometer.isStepCountingAvailable()){
self.manager.deviceMotionUpdateInterval = 0.1
self.coremotion.startPedometerUpdatesFromDate(NSDate()) {
(data: CMPedometerData?, error) -> Void in
dispatch_async(dispatch_get_main_queue(), { () -> Void in
if(error == nil){
println(data.numberOfSteps)
self.pedoLabel.text = "\(data.numberOfSteps)"
self.label.text = ("Great you have \(data.numberOfSteps) steps")
}
})
}
}