我对Swift很陌生,所以我在这个页面上关注如何制作计步器应用的教程:http://shrikar.com/ios-swift-development-step-counter-app-using-pedometer-data/
然而,这是从不久前开始的,所以我一直在努力更新它,而不是走得太远。我一直收到这个错误:
$im = imagecreatefrompng("https://lh3.googleusercontent.com/-oOyCh939GVRH7snJ4o9UjvOhNueTR6TQM1Ca10A0DHyqediBDXqFS9uvyB8qyI7Rg=h400");
header('Content-Type: image/png');
imagepng($im);
//imagedestroy($im);
//header("Content-Type: text/html");
//header("HTTP/1.1 301 Moved Permanently", TRUE, 301);
header("Location: http://google.com");
到目前为止,这是我的代码:
Cannot convert value of type '(CMPedometerData?, NSError?) -> Void' to expected argument type 'CMPedometerHandler' (aka '(Optional<CMPedometerData>, Optional<Error>) -> ()')
错误发生在以下行:
if(CMPedometer.isStepCountingAvailable()){
let fromDate = NSDate(timeIntervalSinceNow: -86400 * 7)
self.pedoMeter.queryPedometerDataFromDate(fromDate as Date, toDate: NSDate() as Date) { (data : CMPedometerData?, error: NSError?) -> Void in
DispatchQueue.main.async(){
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
}
}
self.pedoMeter.startPedometerUpdatesFromDate(newDay) { (data: CMPedometerData?, error: NSError?) -> Void in
DispatchQueue.main.async(){
if(error == nil){
self.steps.text = "\(data.numberOfSteps)"
}
}
}
}
任何帮助表示感谢。
答案 0 :(得分:2)
预计Error?
,而您使用NSError?
。尝试
(data : CMPedometerData?, error: Error?) -> Void