I got this error, and how can I solve this error? When I run the app it crashes. It gives that error, Can anyone help? Thanks in advance.
The error is at the line: let initialAttitude = manager.deviceMotion!.attitude
// get magnitude of vector via Pythagorean theorem
func magnitudeFromAttitude(attitude: CMAttitude) -> Double {
return sqrt(pow(attitude.roll, 2) + pow(attitude.yaw, 2) + pow(attitude.pitch, 2))
}
// initial configuration
let initialAttitude = manager.deviceMotion!.attitude //THIS IS THE LINE OF CODE WITH THE ERROR
var showingPrompt = false
// trigger values - a gap so there isn't a flicker zone
let showPromptTrigger = 1.0
let showAnswerTrigger = 0.8
if manager.deviceMotionAvailable {
manager.startDeviceMotionUpdatesToQueue(NSOperationQueue.mainQueue()) {
[weak self] (data: CMDeviceMotion?, error: NSError?) in
guard let data = data else { return }