我正在使用核心数据将信息保存到对象,但是当我尝试使用它时,程序崩溃并说“致命错误:在解包可选值时意外发现零”我使用coreData保存数据,但对象保持无
这就是我产生
func generateTestData()
{
let item = Item(context: context)
item.title = "New Iphone 7s"
item.price = 2000
item.details = "I wish it's something that is worth to apple , unline Iphone 7"
let item2 = Item(context: context)
item2.title = "Beach House in France"
item2.price = 3000000
item2.details = "I will live there for the rest of my Life , untill then i don't have a life"
}
这是取功能
func attemptFetch()
{
let fetchRequest :NSFetchRequest<Item> = Item.fetchRequest()
let datasort = NSSortDescriptor(key: "created", ascending: false)
fetchRequest.sortDescriptors = [datasort]
let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
self.controller = controller
do{
try controller.performFetch()
}
catch{
let error = error as NSError
print(error.debugDescription)
}
}
坠机发生在这里,当我尝试更新我的视图中的数据
func configureCell(cell : objectItemCell , indexPath :IndexPath)
{
let item = controller.object(at:indexPath)
cell.configureCell(item: item)
}
UITableViewCell类,
func configureCell(item : Item)
{
self.title.text = item.title
self.price.text = "$\(item.price)"
self.details.text = item.details
}
这意味着什么是零。试着找出哪个属性是零,哪条线正是导致崩溃。 – Larme
那个说self.title.text = item.title,其余的同样去下 –
但是这是否意味着'item'是零?那个'item.title'是零,或者'self.title'是零?这是不同的情况,无论这个问题是在CoreData端还是在Cell端。 – Larme