Xcode 初心者です。
テキストラベルに文字を打ち込んで、その文字がTableViewに表示させる、簡単なToDoリストを、フレイムワークRealmを使って作成しております。
ViewController.swift
1import UIKit 2import RealmSwift 3 4class ViewController: UIViewController { 5 6 7 @IBOutlet weak var todoNameText: UITextField! 8 9 10 @IBOutlet weak var tableView: UITableView! 11 12 var toDoItems:Results<ToDo>?{ 13 do{ 14 let realm = try Realm() 15 return realm.objects(ToDo.self) 16 }catch{ 17 print("エラー") 18 } 19 return nil 20 } 21 22 23 24 override func viewDidLoad() { 25 super.viewDidLoad() 26 // Do any additional setup after loading the view. 27 } 28 29 override func didReceiveMemoryWarning() { 30 super.didReceiveMemoryWarning() 31 // Dispose of any resources that can be recreated. 32 } 33 34 35 36 @IBAction func addToDo(_ sender: UIButton) { 37 38 // 入力チェック 39 if isValidateInputContents() == false{ 40 return 41 } 42 43 // ToDoデータを作成する処理 44 let toDo = ToDo() 45 toDo.name = todoNameText.text! 46 47 // ToDoデータを永続化する処理 48 do{ 49 let realm = try Realm() 50 try realm.write{ 51 realm.add(toDo) 52 } 53 todoNameText.text = "" 54 }catch{ 55 print("失敗") 56 } 57 tableView.reloadData() 58 } 59 60 61 private func isValidateInputContents() -> Bool{ 62 // ToDo名のデータ入力 63 if let name = todoNameText.text{ 64 if name.count == 0{ 65 return false 66 } 67 }else{ 68 return false 69 } 70 return true 71 } 72} 73 74 75extension ViewController:UITableViewDataSource{ 76 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 77 return toDoItems!.count 78 } 79 80 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 81 82 let toDo = toDoItems?[indexPath.row] 83 84 85 let cell = tableView.dequeueReusableCell(withIdentifier: ("cell"), for: indexPath) 86 87 88 cell.textLabel!.text = toDo?.name 89 90 print(toDo?.name as Any) 91 92 return cell 93 } 94} 95コード
ToDo.swift
1import Foundation 2import RealmSwift 3 4class ToDo: Object{ 5 /// 名前 6 dynamic var name = "" 7 /// 期限 8 dynamic var deadLine = NSDate(timeIntervalSince1970: 0) 9 /// 完了フラグ 10 dynamic var isComplete = false 11}
コード
ToDoTableViewCell.swift
1import UIKit 2 3 4class ToDoTableViewCell: UITableViewCell { 5 6 7 @IBOutlet weak var nemeLabel: UILabel! 8 9 10 11 override func awakeFromNib() { 12 super.awakeFromNib() 13 // Initialization code 14 } 15 16 override func setSelected(_ selected: Bool, animated: Bool) { 17 super.setSelected(selected, animated: animated) 18 19 // Configure the view for the selected state 20 } 21 22} 23 24コード
しかし、シミュレータを立ち上げラベルに文字を打ち込み、ボタンを押すと強制終了し、以下の様なエラーが出ます。どうすれば解決できるでしょうか?
Thread 1: signal SIGABRT
なんども設定を確認しましたが解決しておりません。
初歩の初歩のミスだと思うのですが、宜しくお願いします。
Thread 1: signal SIGABRT
は、強制終了のシグナルが出ました。と書かれているだけで、
実際のエラーではありません。
その前のエラーの内容を英語を頑張って読んでみて、ここに追記してください。
Xcode上のソースコード下部に表示されるエラーをすべて追記してください
こちらでしょうか?
2019-08-20 15:36:00.412518+0900 swip-d4[76900:6730633] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/kojitakemura/Library/Developer/CoreSimulator/Devices/91AF13F2-B15D-4CB1-A6B2-EF1EEA401E15/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-08-20 15:36:00.413982+0900 swip-d4[76900:6730633] [MC] Reading from private effective user settings.
2019-08-20 15:36:05.678108+0900 swip-d4[76900:6730633] *** Terminating app due to uncaught exception 'RLMException', reason: 'Table has no columns
Exception backtrace:
0 Realm 0x000000010848fda1 _ZN5realm4util6detail26ExceptionWithBacktraceBaseC2Ev + 49
1 Realm 0x00000001084904d6 _ZN5realm4util22ExceptionWithBacktraceISt9exceptionEC2IJEEEDpOT_ + 38
2 Realm 0x0000000108490482 _ZN5realm10LogicErrorC2ENS0_9ErrorKindE + 34
3 Realm 0x00000001084903fb _ZN5realm10LogicErrorC1ENS0_9ErrorKindE + 27
4 Realm 0x0000000108a83f8c _ZN5realm5Table16insert_empty_rowEmm + 268
5 Realm 0x0000000108b4b5e9 _ZN5realm4sync13create_objectERKNS0_14TableInfoCacheERNS_5TableE + 137
6 Realm 0x000000010865c264 _ZN5realm6Object6createIU8__strongP11objc_object18RLMAccessorContextEES0_RT0_RKNSt3__110shared_ptrINS_5RealmEEERKNS_12ObjectSchemaET_bbmPNS_8BasicRowINS_5TableEEE + 2452
7 Realm 0x000000010865b6fa RLMAddObjectToRealm + 682
8 RealmSwift 0x0000000109d1efaf $s10RealmSwift0A0C3add_6updateyAA6ObjectC_AC12UpdatePolicyOtF + 1407
9 swip-d4 0x00000001080c9a6f $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFyyXEfU_ + 63
10 swip-d4 0x00000001080c9da1 $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFyyXEfU_TA + 17
11 RealmSwift 0x0000000109d1e1ea $s10RealmSwift0A0C5writeyyyyKXEKF + 90
12 swip-d4 0x00000001080c95eb $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCF + 1019
13 swip-d4 0x00000001080c9acc $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFTo + 60
14 UIKitCore 0x0000000114784624 -[UIApplication sendAction:to:from:forEvent:] + 83
15 UIKitCore 0x00000001141d98d5 -[UIControl sendAction:to:forEvent:] + 67
16 UIKitCore 0x00000001141d9bf2 -[UIControl _sendActionsForEvents:withEvent:] + 450
17 UIKitCore 0x00000001141d8ba8 -[UIControl touchesEnded:withEvent:] + 583
18 UIKitCore 0x00000001147bd4e6 -[UIWindow _sendTouchesForEvent:] + 2547
19 UIKitCore 0x00000001147bebca -[UIWindow sendEvent:] + 4079
20 UIKitCore 0x000000011479d30e -[UIApplication sendEvent:] + 356
21 UIKitCore 0x000000011486d2b3 __dispatchPreprocessedEventFromEventQueue + 3232
22 UIKitCore 0x000000011486fbd9 __handleEventQueueInternal + 5911
23 CoreFoundation 0x000000010b56edb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x000000010b56e633 __CFRunLoopDoSources0 + 243
25 CoreFoundation 0x000000010b568cef __CFRunLoopRun + 1231
26 CoreFoundation 0x000000010b5684d2 CFRunLoopRunSpecific + 626
27 GraphicsServices 0x00000001119ab2fe GSEventRunModal + 65
28 UIKitCore 0x0000000114782fc2 UIApplicationMain + 140
29 swip-d4 0x00000001080cc94b main + 75
30 libdyld.dylib 0x000000010c6f0541 start + 1
31 ??? 0x0000000000000001 0x0 + 1'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b6078db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010a628ac5 objc_exception_throw + 48
2 Realm 0x000000010865b78b RLMAddObjectToRealm + 827
3 RealmSwift 0x0000000109d1efaf $s10RealmSwift0A0C3add_6updateyAA6ObjectC_AC12UpdatePolicyOtF + 1407
4 swip-d4 0x00000001080c9a6f $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFyyXEfU_ + 63
5 swip-d4 0x00000001080c9da1 $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFyyXEfU_TA + 17
6 RealmSwift 0x0000000109d1e1ea $s10RealmSwift0A0C5writeyyyyKXEKF + 90
7 swip-d4 0x00000001080c95eb $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCF + 1019
8 swip-d4 0x00000001080c9acc $s7swip_d414ViewControllerC7addToDoyySo8UIButtonCFTo + 60
9 UIKitCore 0x0000000114784624 -[UIApplication sendAction:to:from:forEvent:] + 83
10 UIKitCore 0x00000001141d98d5 -[UIControl sendAction:to:forEvent:] + 67
11 UIKitCore 0x00000001141d9bf2 -[UIControl _sendActionsForEvents:withEvent:] + 450
12 UIKitCore 0x00000001141d8ba8 -[UIControl touchesEnded:withEvent:] + 583
13 UIKitCore 0x00000001147bd4e6 -[UIWindow _sendTouchesForEvent:] + 2547
14 UIKitCore 0x00000001147bebca -[UIWindow sendEvent:] + 4079
15 UIKitCore 0x000000011479d30e -[UIApplication sendEvent:] + 356
16 UIKitCore 0x000000011486d2b3 __dispatchPreprocessedEventFromEventQueue + 3232
17 UIKitCore 0x000000011486fbd9 __handleEventQueueInternal + 5911
18 CoreFoundation 0x000000010b56edb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010b56e633 __CFRunLoopDoSources0 + 243
20 CoreFoundation 0x000000010b568cef __CFRunLoopRun + 1231
21 CoreFoundation 0x000000010b5684d2 CFRunLoopRunSpecific + 626
22 GraphicsServices 0x00000001119ab2fe GSEventRunModal + 65
23 UIKitCore 0x0000000114782fc2 UIApplicationMain + 140
24 swip-d4 0x00000001080cc94b main + 75
25 libdyld.dylib 0x000000010c6f0541 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
> reason: 'Table has no columns
ここから何かわかりませんかね??