Swift 3 迁移:无法推断通用参数 'Element'
Swift 3 Migration: Generic parameter 'Element' could not be inferred
arrayOfDicts 声明为
let accelManager = CMSensorRecorder()
let motionManager = CMMotionManager()
var arrayOfDicts:[NSDictionary] = []
函数定义为
func startMotionManager() {
WKInterfaceDevice.current().play(.start)
self.arrayOfDicts = []
if motionManager.isAccelerometerAvailable {
motionManager.accelerometerUpdateInterval = 0.01
let handler:CMAccelerometerHandler = {(data: CMAccelerometerData?, error: NSError?) -> Void in
self.arrayOfDicts.append([
"timestamp":data!.timestamp,
"x":data!.acceleration.x,
"y":data!.acceleration.y,
"z":data!.acceleration.z
])
//print("timestamp: ", data!.timestamp, ", x: ", data!.acceleration.x, ", y: ", data!.acceleration.y, ", z: ", data!.acceleration.z)
}
motionManager.startAccelerometerUpdates(to: OperationQueue(), withHandler: handler)
}
}
错误发生在 "let handler" 行。
“无法推断通用参数 'Element'
在调用函数 'append'"
我查了一下,认为这是因为编译器不确定数组 "arrayOfDicts" 是什么类型……但我可能离题太远了。任何关于此主题的and/or教育帮助都将不胜感激。
-马特
关闭类型 CMAccelerometerHandler
已更改为:
public typealias CMAccelerometerHandler = (CMAccelerometerData?, Error?) -> Swift.Void
(来自 "CMMotionManager.h" 的生成 header。)
尝试将该行中的 NSError?
更改为 Error?
。
您有时可能需要将 "cannot be inferred" 之类的错误消息视为 "there may be some type related errors"。发送 bug report to promote Apple (or swift.org) 以改进此类诊断。
arrayOfDicts 声明为
let accelManager = CMSensorRecorder()
let motionManager = CMMotionManager()
var arrayOfDicts:[NSDictionary] = []
函数定义为
func startMotionManager() {
WKInterfaceDevice.current().play(.start)
self.arrayOfDicts = []
if motionManager.isAccelerometerAvailable {
motionManager.accelerometerUpdateInterval = 0.01
let handler:CMAccelerometerHandler = {(data: CMAccelerometerData?, error: NSError?) -> Void in
self.arrayOfDicts.append([
"timestamp":data!.timestamp,
"x":data!.acceleration.x,
"y":data!.acceleration.y,
"z":data!.acceleration.z
])
//print("timestamp: ", data!.timestamp, ", x: ", data!.acceleration.x, ", y: ", data!.acceleration.y, ", z: ", data!.acceleration.z)
}
motionManager.startAccelerometerUpdates(to: OperationQueue(), withHandler: handler)
}
}
错误发生在 "let handler" 行。
“无法推断通用参数 'Element' 在调用函数 'append'"
我查了一下,认为这是因为编译器不确定数组 "arrayOfDicts" 是什么类型……但我可能离题太远了。任何关于此主题的and/or教育帮助都将不胜感激。
-马特
关闭类型 CMAccelerometerHandler
已更改为:
public typealias CMAccelerometerHandler = (CMAccelerometerData?, Error?) -> Swift.Void
(来自 "CMMotionManager.h" 的生成 header。)
尝试将该行中的 NSError?
更改为 Error?
。
您有时可能需要将 "cannot be inferred" 之类的错误消息视为 "there may be some type related errors"。发送 bug report to promote Apple (or swift.org) 以改进此类诊断。