Swift gyroscope yaw, pitch, roll

I'm doing a project for my school, for a programming subject. I'm working in Xcode in Swift. I would like to make an application that uses Gyroscope. I don't know but somehow it won't run on my iphone because of some errors in Xcode that I don't know how to fix.When I run the program is says "fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)"
The main thing of my project is to display rotations (yaw,pitch,roll) in degrees on iphone screen using gyroscope. I would be really grateful if someone help me with this. Thank you in advance.

In these two lines you're working with implicitly unwrapped optionals: you use them without ? or !, but they'll crash your program if they're nil. In this case, motionManager.deviceMotion is nil because you haven't called motionManager.startDeviceMotionUpdates() prior to that access.