我正在开发一个 iOS 应用程序,我刚刚切换到 Swift 3.0,所以现在我的代码中有很多错误,我不知道如何修复其中一些错误。
1) 此代码段第二行出现错误“参数标签 '(fileURLwithPathComponents:)' 与任何可用的重载不匹配”:
let pathArray = [dirPath, recordingName]
let filePath = URL(fileURLwithPathComponents: pathArray)
2) 错误“无法转换类型‘(CMAccelerometerData?,NSError?)->()”的值 到预期的参数类型“CMAccelermeterHandler”(又名(“可选,可选)->()”)“
motionManager.startAccelerometerUpdates(to: OperationQueue.main) {
[weak self] (data: CMAccelerometerData?, error: NSError?) in self!.label.text = "started tracking"
最佳答案
感谢@Koen 和@Larme,我找到了这两个问题的解决方案:
1) 让 filePath = NSURL.fileURL(withPathComponents: pathArray)
2) 应该只是“Error”而不是“NSError”
关于swift 3.0 语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40514924/