无法删除Core Data中具有nil字段的对象

时间:2015-04-15 17:52:14

标签: ios swift core-data

每当我在核心数据中创建一个新实体并保存第一个对象时,实体总是返回保存的对象和一个所有fields = nil的对象。如果我尝试迭代实体中的所有对象并删除,除了nil对象之外,所有具有数据删除的对象都是如此,所以问题是这个字段的nil值始终存在。

任何意见都赞赏。

//get context

        var appDel : AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate;

        var context : NSManagedObjectContext = appDel.managedObjectContext!;

        var newEntry3 = NSEntityDescription.insertNewObjectForEntityForName("TestParse", inManagedObjectContext: context) as NSManagedObject;

        var error : NSError? = nil;



        //Fetch request

        var request = NSFetchRequest(entityName: "TestParse");

        // for beta 4 xcode only
        request.returnsObjectsAsFaults = false;

        var results  = context.executeFetchRequest(request, error: nil);

        println("\n\nResults from DB \(results?.count) and teh results object \(results)\n\n");

        if results?.count > 0{




            for result : AnyObject in results! {


                println("Database object form parse: \(result.count) and contents : \(result.description)");


              // delet object and save for debugging an delete the 'nil' object                  context.deleteObject(result as NSManagedObject);

               context.save(&error);
                println("DELETED CORE DATA OBJECT : \(result)");

0 个答案:

没有答案