核心数据EXC_BREAKPOINT

时间:2015-04-03 20:17:30

标签: swift core-data

以下是我在整个项目中使用的代码,没有任何问题:

var results: NSArray = context.executeFetchRequest(request, error: &error)!

然而它崩溃了!任何想法为什么?? 更多代码:

//now get old current and revoke that

            var context:NSManagedObjectContext = self.appDel.managedObjectContext!



            var request = NSFetchRequest(entityName: "DownloadedCharacters")

            request.returnsObjectsAsFaults = false

            request.predicate = NSPredicate(format: "isCurrent = %@", true)



            var results: NSArray = context.executeFetchRequest(request, error: &error)!



            //error check

            if results.count == 1 {

                //good

                let object:NSManagedObject = results[0] as NSManagedObject

                object.setValue(false, forKey: "isCurrent")

                println("Revoked old current Object, 1")

                //update currents

                //find the new object in storage based off saved name

                let lookupName = cell.cellData?.valueForKey("saveName") as String

                var request2 = NSFetchRequest(entityName: "DownloadedCharacters")

                request2.returnsObjectsAsFaults = false

                request2.predicate = NSPredicate(format: "saveName = %@", lookupName)

                var results2:NSArray = context.executeFetchRequest(request2, error: &self.error)!

                if results2.count == 1 {

                    let object = results2.firstObject as NSManagedObject

                    object.setValue(true, forKey: "isCurrent")

                    println("Updated new current")     

                } else {

                    println("Fatal error in retreving object for Core Data. Count = \(results.count).")

                }

                //now update the section of the table

                tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITableViewRowAnimation.Automatic)


            }

非常令人沮丧。此外,在有问题的行后,println(“撤销旧的当前对象,1”)被调用和IS打印到控制台..........任何帮助将不胜感激

0 个答案:

没有答案