Error: value of optional type 'NSOperationQueue?' not unwrapped; did you man to use '!' or '?'?

Error: value of optional type 'NSOperationQueue?' not unwrapped; did you man to use '!' or '?'?

所以,我正在尝试从加速度计传感器获取数据,但即使我尝试了“!”,我仍然会收到此错误。和 '?'和 'if let'。我想不出尝试其他任何东西,奇怪的是,相同的代码可以在我获得它的 youtube 教程上运行。 这是代码:

// Instance variables
var currentMaxAccelY: Double = 0.0
var currentMaxAccelZ: Double = 0.0
lazy var motionManager = CMMotionManager()

// functions
override func viewDidLoad() {
currentMaxAccelY = 0.0
currentMaxAccelZ = 0.0

    // Do any additional setup after loading the view.
    //video version
    if (self.motionManager.accelerometerAvailable) {

    self.motionManager.accelerometerUpdateInterval = 0.2
    self.motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()){[weak self](accelerometerData: CMAccelerometerData!, error: NSError!) in //here i get the error
        self.outputAccelerationData(accelerometerData.acceleration)
         if (error != nil){
         print("\(error)")

            }
        }
   }

   else {
        print("accelerometer not available")
    }

    super.viewDidLoad()

}

func outputAccelerationData(acceleration: CMAcceleration){
    jumpCounter?.text = "\(acceleration.z).2fg"
    y?.text = "\(acceleration.y).2fg"
    if fabs(acceleration.y) > fabs(currentMaxAccelY) {
        currentMaxAccelY = acceleration.y
    }
    if fabs(acceleration.z) > fabs(currentMaxAccelZ) {
        currentMaxAccelY = acceleration.z
    }
    yMax?.text = "\(currentMaxAccelY).2f"
    zMax?.text = "\(currentMaxAccelZ).2f"

}

非常感谢任何帮助..

对我有用

let motionManager = CMMotionManager()
if let queue = NSOperationQueue.currentQueue() {
    motionManager.startAccelerometerUpdatesToQueue(queue) { (data, error) -> Void in }
}