我喜欢将行移至bottomtable,然后将其移至persist,这就是我希望再次进入屏幕时看到的更改(如果eventStatus == 1 0r 2)。我做了以下但行不动

        if eventSegCtrl.selectedSegmentIndex == 0 {
        myEventCell.eventLabel.text = self.eventScheduleOnc[indexPath.row].eventNameOnc
        let eventDesc = self.eventScheduleOnc[indexPath.row].eventDecOnc
            let eventStatus = eventDesc?.eventStatus

           if eventStatus == 1 {
                myEventCell.eventLabel.textColor = UIColor.green
                do
                {
            //Create fetch request with NSSortDescriptor
                    let request = NSFetchRequest<NSFetchRequestResult>(entityName: "EventScheduleOnc")
                    let sort = NSSortDescriptor(key: "indexOnc", ascending: true)
                    request.sortDescriptors = [sort]

             //   Acess the last objects index
                    let lastRowIndex = eventTitleOnc.count - 1
                    print(lastRowIndex)
                    request.setValue(lastRowIndex, forKey: "indexOnc")

              // Save it to core data
                   try context.save()
                _ = try context.execute(request)

                }
                catch{}
        }


我收到以下错误


  ***由于未捕获的异常'NSUnknownKeyException'而终止应用程序,原因:'[setValue:forUndefinedKey:]:
  此类与键indexOnc的键值编码不兼容。”

最佳答案

您试图在NSFetchRequest的以下行中设置一个值,该值未完成:request.setValue(lastRowIndex, forKey: "indexOnc")。该请求将没有您的属性之一的密钥。不确定您要使用它做什么。

关于swift - 提取时与键值编码兼容的错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42867746/

10-08 20:53