JThora JThora - 1 month ago 25
Swift Question

Error: 'NSOperationQueue' has been renamed to OperationQueue

In Xcode 8.0, I'm getting an error while compiling for Swift 3.0

Error: "'NSOperationQueue' has been renamed to OperationQueue"

When I switch to OperationQueue.mainQueue() the method "mainQueue" doesn't exist! What's replaced it???

let manager = CMMotionManager()
if manager.isGyroAvailable {
manager.gyroUpdateInterval = 0.1
manager.startGyroUpdates()
let queue = NSOperationQueue.mainQueue()
manager.startGyroUpdatesToQueue(queue) {
(data, error) in
// ...
}
}
if manager.isAccelerometerAvailable {
manager.accelerometerUpdateInterval = 0.01
manager.startAccelerometerUpdatesToQueue(NSOperationQueue.mainQueue()) {
[weak self] (data: CMAccelerometerData?, error: NSError?) in
if let acceleration = data?.acceleration {
self.physicsWorld.gravity = CGVectorMake(acceleration.x, acceleration.y)
}
}
}


How to I fix the above code so NSOperationQueues are formatted correctly?

Answer

Write OperationQueue.main.

Fairly simple.

Comments