startAccelerometerUpdatesToQueue Type of expression is ambiguous without more context

1.2k views Asked by At

I am trying to translate the following code to Swift 2.

manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { [weak self] (data: CMAccelerometerData!, error: NSError!) in              
    self!.outputAccData(data.acceleration)
}

But this gives me the following error.

Type of expression is ambiguous without more context

Does anyone know why this is happening?

1

There are 1 answers

0
Mick MacCallum On BEST ANSWER

This is one of those problems that can be solved by retyping the code from scratch. It appears that the second parameter to startAccelerometerUpdatesToQueue() is now an object of type (CMAccelerometerData?, NSError?) -> Void instead of (CMAccelerometerData!, NSError!) -> Void. You just need to rewrite your call to reflect this.

manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) { [weak self] (data: CMAccelerometerData?, error: NSError?) in
    self!.outputAccData(data.acceleration)
}