【发布时间】:2017-02-14 19:53:41
【问题描述】:
我的一张表有以下代码。
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 上遇到运行时错误
上面写着 Thread 1: EXC_BAD_ACCESS (error: CoreData: error: Failed to call specified initializer on NSManagedObject class )
它在 swift 2 中没有这样做,所以不确定错误是什么。我将截取我的模型和创建的类。
我不知道如何修复该错误,因为这之前有效。发生了什么变化?
【问题讨论】:
-
不知道你是否在“InventoryTableViewCell”类中初始化了变量“inventoryItem”。如果您已启动此操作,请将其更改为可选变量。它也可能导致同样的问题。
标签: swift core-data swift2 swift3 ios10