JThora JThora - 1 year ago 195
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
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 Source

Write OperationQueue.main.

Fairly simple.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download