iPhone X で実行すると成功するのですが、ipadや違うiphoneで試すとエラーが発生してしまいます。@IBAction func save(_ sender: Any)のところで発生してしますのですが、iphoneX以外で発生している原因を教えていただきたいです。
swift
1 2 var resultArray1 = [String]() 3 4 var dateArray1 = [String]() 5 6 var Array1: [[String]] = [] 7 8 var date1 = Date() 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 //timerLabelのfont 14 timerLabel2.font = font1 15 //fractionsLabelのfont 16 fractionsLabel2.font = font2 17 //countLabelのfont 18 countLabel2.font = font3 19 20 let label = UILabel.init() 21 label.adjustsFontSizeToFitWidth = true 22 label.minimumScaleFactor = 0.3 23 24 let button = UIButton.init() 25 button.titleLabel?.adjustsFontSizeToFitWidth = true 26 button.titleLabel?.minimumScaleFactor = 0.3 27 28 let secondsString3 = secondsString2 > 9 ? "(secondsString2)" : "0(secondsString2)" 29 let minutesString3 = minutesString2 > 9 ? "(minutesString2)" : "0(minutesString2)" 30 let fractionsString3 = fractionsString2 > 9 ? "(fractionsString2)" : "0(fractionsString2)" 31 32 countLabel2.text = String(countLabelText) 33 timerLabel2.text = "(minutesString3):(secondsString3)" 34 fractionsLabel2.text = ".(fractionsString3)" 35 36 if fractionsString2 == 0 { 37 fractionsLabel2.text = ".00" 38 } 39 40 41 } 42 43 @IBAction func save(_ sender: Any) { 44 45 //配列を取り出す 46 if (UserDefaults.standard.object(forKey: "save") != nil) { 47 Array1 = UserDefaults.standard.object(forKey: "save") as! [[String]]**Thread 1: signal SIGABRT** 48 49 } 50 51 //Array1の要素0(resultArray1の保存したもの)をresultArray1に入れる 52 self.resultArray1 = self.Array1[0]**index out of range** 53 // Array1の要素1(dateArray1の保存したもの)をdateArray1に入れる 54 self.dateArray1 = self.Array1[1] 55 56 //zikanを呼び出す 57 zikan() 58 //resultArrayに回数を追加 59 resultArray1.append(countLabel2.text!) 60 61 Array1 = [resultArray1, dateArray1] 62 63 UserDefaults.standard.set(Array1, forKey: "save") 64 65 //print("Array1:", resultArray1.count) 66 67 68 } 69 70 71 func zikan() { 72 //日付のフォーマットを指定する 73 let format = DateFormatter() 74 format.dateFormat = DateFormatter.dateFormat(fromTemplate: "yMdkHm", options: 0, locale: Locale(identifier: "ja_JP")) 75 76 //日付をStringに変換する 77 let sDate = format.string(from: date1) 78 //日付をdateArrayに入れる 79 dateArray1.append(sDate) 80 } 81 82 83 84 85 /* 86 // MARK: - Navigation 87 88 // In a storyboard-based application, you will often want to do a little preparation before navigation 89 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 90 // Get the new view controller using segue.destination. 91 // Pass the selected object to the new view controller. 92 } 93 */ 94 95} 96
エラーの内容を書いて下さい。
Thread 1: signal SIGABRT
またはindex out of rangeです。
シミュレーターを変えるとどちらかが出ます。
エラーが出ている行を正確に書いて下さい。
Array1 = UserDefaults.standard.object(forKey: "save") as! [[String]]**Thread 1: signal SIGABRT**
}
//Array1の要素0(resultArray1の保存したもの)をresultArray1に入れる
self.resultArray1 = self.Array1[0]**index out of range**
あー、ソース内に書かれていますね。
もう少し目立つように書くか、該当部分を抜粋して欲しいです。
ソース内への埋め込みだけだと把握しづらいです。
回答1件
あなたの回答
tips
プレビュー