###前提・実現したいこと
textviewに配列に格納した加速度を時間ごとに見やすく表示させたい
###発生している問題・エラーメッセージ
コンパイルは通るのですがThread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional valueが出て動きません。多分self.~のところで何か起きてると思うのですが何がいけないのかわかりません
エラーメッセージ ```Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value ###該当のソースコード ```swift4 import UIKit import CoreMotion class ViewController: UIViewController { let motionManager = CMMotionManager() var dataX:[Double] = [] var dataY:[Double] = [] var dataZ:[Double] = [] @IBOutlet weak var accelX: UILabel! @IBOutlet weak var accelY: UILabel! @IBOutlet weak var accelZ: UILabel! @IBOutlet weak var TextView: UITextView! override func viewDidLoad() { super.viewDidLoad() if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.2 motionManager.startAccelerometerUpdates( to: OperationQueue.current!, withHandler: {(accelData: CMAccelerometerData?, errorOC: Error?) in self.outputAccelData(acceleration: accelData!.acceleration) }) } } func outputAccelData(acceleration: CMAcceleration){ accelX.text = String(format: "x = %.4f", acceleration.x) accelY.text = String(format: "y = %.4f", acceleration.y) accelZ.text = String(format: "z = %.4f", acceleration.z) dataX.append(acceleration.x) dataY.append(acceleration.y) dataZ.append(acceleration.z) TextView.text = String(format: "%.2f %.2f %.2f\n",dataX,dataY,dataZ) if ((acceleration.x >= 1.0)||(acceleration.x <= -1.0)) { accelX.textColor = UIColor.red } else if((acceleration.x <= 1.0)||(acceleration.x >= -1.0)) { accelX.textColor = UIColor.black } if((acceleration.y >= 1.0)||(acceleration.y <= -1.0)) { accelY.textColor = UIColor.red } else if((acceleration.y <= 1.0)||(acceleration.y >= -1.0)) { accelY.textColor = UIColor.black } if((acceleration.z >= 1.0)||(acceleration.z <= -1.0)) { accelZ.textColor = UIColor.red } else if((acceleration.z <= 1.0)||(acceleration.z >= -1.0)) { accelZ.textColor = UIColor.black } } func stopAccelerometer(){ if (motionManager.isAccelerometerActive) { motionManager.stopAccelerometerUpdates() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }
###試したこと
エラーメッセージや似たような事例がないかネットで検索してみました
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/20 05:23