2016-10-06 3 views
1

테이블 중 하나에 다음 코드가 있습니다. EXC_BAD_ACCESS (오류 : CoreData : 오류 : NSManagedObject 클래스의 지정 초기화를 호출하지 못했습니다)스위프트 2에서 3으로 마이그레이션 핵심 데이터 NSManagedObject 클래스

그것은하지 않았다

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "InventoryTableCell", for: indexPath as IndexPath) as! InventoryTableViewCell 

     let inventory : Inventory = fetchedResultsController.object(at: indexPath as IndexPath) as! Inventory 
     cell.inventoryItem = inventory 

     cell.drawCell() //uses passed inventoryItem to draw it's self accordingly. 

     return cell 
    } 

내가 cell.inventoryItem = inventory

에 런타임 오류를 받고 있어요 그것은 스레드 1 말한다 신속한 2에서 이렇게하므로 오류가 무엇인지 확실하지 않습니다. 내 모델의 스크린 샷을 찍어 수업을 만들겠습니다.

이전에 작동 했으므로 오류 수정 방법을 모릅니다. 무엇이 바뀌 었습니까?

enter image description here enter image description here enter image description here

+0

"InventoryTableViewCell"클래스에서 "inventoryItem"변수를 초기화했는지 여부를 알 수 없습니다. 이 작업을 시작한 경우 옵션 변수로 변경하십시오. 같은 문제가 발생할 수도 있습니다. –

답변

1

난 당신이 항목을 정의 할 때 지금에 대한 컨텍스트를 제공해야하거나 작동하지 않습니다, 내 문제를 해결 같은데.

여기 InventoryTableViewCell에 표시하지 않은 코드에서 inventoryItem을 잘못 정의했습니다.

올바른 방법은 다음과 같습니다.

//Set inventory item as an InventoryType within the correct context 
    var inventoryItem = Inventory(context: (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext) 
관련 문제