swift 3.0 语法问题

标签 swift swift3

我正在开发一个 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/

相关文章:

ios - MKMapView 选择注解

ios - 关闭和呈现 MFMessageComposeViewController

ios - 从另一个 pickerView 选择项目时隐藏 pickerView 的行

ios - 设计带有角边框的 View swift 3

swift - 如何快速将数据转换为十六进制字符串

ios - 在 swift 3 中从另一个 View 中选择某些内容后,更新一个打开的 View 中按钮中的文本

ios - 快速暂停无尽的 SKAction

ios - @Observable 没有完全按要求工作

Swift 3 - 原子 boolean 值

ios - tableview 数据无法在 swift 中正确显示