I am converting an app from swift 2 to swift 3 and I\'m trying to use the CMMotionManager, but it gives me this error when I try to call the .startAccelerometerUpdates() functio
The cryptic error message boils down to this: in Swift 3 NSError
is bridged to Error
instead. Write your code like this and the problem should go away:
motionManager.startAccelerometerUpdates(to: OperationQueue.main) { [weak self] (data: CMAccelerometerData?, error: Error?) in
There are many changes in Swift3. Especially in expressions. Many NS suffix of types are removed such as NSError
to Error, NSData
to Data.
Therefore, change NSError
to Error
. And if you want to prevent performance issue by multiple instances of CMMotionManager
, use SwiftyMotionManager.