I am making simple app now.
I made some cells and buttons on my simple app.
but I met this error message:
libc++abi.dylib: terminating with uncaught exception of type NSException
some people who have that error message already asked it.
I have read their questions... but there is no one who have same problem to mine.
and there is that problem in AppDelegate class
I will show you my code..
lazy var list: [NSManagedObject] = {
return self.fetch()
}()
//데이터를 읽어올 메소드
func fetch() -> [NSManagedObject] {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 요청 객체 생성
let fetchRequest = NSFetchRequest<NSManagedObject>(entityName: "Board")
//3-1 정렬 속성 설정
let sort = NSSortDescriptor(key: "regdate", ascending: false)
fetchRequest.sortDescriptors = [sort]
//4 데이터 가져오기
let result = try! context.fetch(fetchRequest)
return result
}
//데이터를 저장할 메소드
func save(title: String, contents: String) -> Bool {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 관리 객체 생성 & 값을 설정
let object = NSEntityDescription.insertNewObject(forEntityName: "Board", into: context)
object.setValue(title, forKey: "title")
object.setValue(contents, forKey: "contents")
object.setValue(Date(), forKey: "regdate")
//4 영구 저장소에 커밋되고 나면 list 프로퍼팅 추가한다.
do {
try context.save()
//self.list.append(object)
self.list.insert(object, at: 0)
return true
} catch {
context.rollback()
return false
}
}
//화면 및 로직 초기화 메소드
override func viewDidLoad() {
let addBtn = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(add(_:)))
self.navigationItem.rightBarButtonItem = addBtn
}
//데이터 저장 버튼에 대한 액션 메소드
@objc func add(_ sender: Any) {
let alert = UIAlertController(title: "게시글 등록", message: nil, preferredStyle: .alert)
//입력 필드 추가(이름 & 전화번호)
alert.addTextField() {$0.placeholder = "제목"}
alert.addTextField() {$0.placeholder = "내용"}
//버튼 추가 (cancel & save)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alert.addAction(UIAlertAction(title: "Save", style: .default) {(_) in
guard let title = alert.textFields?.first?.text, let contents = alert.textFields?.last?.text else {
return
}
//값을 저장하고 성공이면 테이블 뷰를 리로드한다.
if self.save(title: title, contents: contents) == true {
self.tableView.reloadData()
}
})
self.present(alert, animated: false)
}
func delete(object: NSManagedObject) -> Bool {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 컨텍스트로부터 해당 객체 삭제
context.delete(object)
//4 영구저장소에 커밋한다.
do {
try context.save()
return true
} catch {
context.rollback()
return false
}
}
//데이터 수정 처리를 담당할 edit메소드 구현
func edit(object: NSManagedObject, title: String, contents: String) -> Bool {
//1 앱 델리게이트 객체 참조
let appDelegate = UIApplication.shared.delegate as! AppDelegate
//2 관리 객체 컨텍스트 참조
let context = appDelegate.persistentContainer.viewContext
//3 관리 객체의 값을 수정
object.setValue(title, forKey: "title")
object.setValue(contents, forKey: "contents")
object.setValue(Date(), forKey: "regdate")
//영구 저장소에 반영한다.
do {
try context.save()
self.list = self.fetch()
return true
} catch {
context.rollback()
return false
}
}
and this is my full error message 2018-01-23 21:38:58.066127+0900 Chapter07-CoreData[2427:173395] * Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3694.4.18/UITableView.m:7732 2018-01-23 21:38:58.072324+0900 Chapter07-CoreData[2427:173395] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' *** First throw call stack: ( 0 CoreFoundation 0x0000000113eec1cb exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010ffccf41 objc_exception_throw + 48 2 CoreFoundation 0x0000000113ef1362 +[NSException raise:format:arguments:] + 98 3 Foundation 0x000000010fa71089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4 UIKit 0x0000000110c20968 -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 890 5 UIKit 0x0000000110c205ba -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 89 6 Chapter07-CoreData 0x000000010f6a80ab _T018Chapter07_CoreData6ListVCC9tableViewSo07UITableG4CellCSo0hG0C_10Foundation9IndexPathV12cellForRowAttF + 2123 7 Chapter07-CoreData 0x000000010f6a866c _T018Chapter07_CoreData6ListVCC9tableViewSo07UITableG4CellCSo0hG0C_10Foundation9IndexPathV12cellForRowAttFTo + 92 8 UIKit 0x0000000110c3bef0 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 727 9 UIKit 0x0000000110c3c4ab -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74 10 UIKit 0x0000000110c02870 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2892 11 UIKit 0x0000000110c23de9 -[UITableView layoutSubviews] + 176 12 UIKit 0x0000000110bb1551 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331 13 QuartzCore 0x00000001174b04ba -[CALayer layoutSublayers] + 153 14 QuartzCore 0x00000001174b45a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401 15 QuartzCore 0x000000011743d1cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365 16 QuartzCore 0x0000000117468ae4 _ZN2CA11Transaction6commitEv + 500 17 UIKit 0x0000000110afe706 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 141 18 CoreFoundation 0x0000000113e8f20c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 19 CoreFoundation 0x0000000113e73a3b __CFRunLoopDoBlocks + 203 20 CoreFoundation 0x0000000113e73214 __CFRunLoopRun + 1300 21 CoreFoundation 0x0000000113e72a89 CFRunLoopRunSpecific + 409 22 GraphicsServices 0x00000001166649c6 GSEventRunModal + 62 23 UIKit 0x0000000110ae2d30 UIApplicationMain + 159 24 Chapter07-CoreData 0x000000010f6b06a7 main + 55 25 libdyld.dylib 0x0000000115015d81 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier **** - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
That's the important part of your message, that's the error. You can search for that. It crashes because of aUITableView
and not correctly setUITableViewCell
but there is absolutely NO mention ofUITableView
in the code you gave. – Larme