如何在NSManagedObjectContext中替换Object

时间:2016-07-23 13:45:49

标签: objective-c object core-data

如何在核心数据对象中用托管对象替换对象。请帮助我如何摆脱这个问题。

XMPPMessageArchivingCoreDataStorage *storage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [storage mainThreadManagedObjectContext];

NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Contact_CoreDataObject"
                                                     inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSSortDescriptor *sortDescriptor1 = [NSSortDescriptor sortDescriptorWithKey:@"mostRecentMessageTimestamp" ascending:NO];
[request setEntity:entityDescription];
[request setSortDescriptors:@[sortDescriptor1]];
NSError *error;

NSArray *data = [moc executeFetchRequest:request error:&error];
for (XMPPMessageArchiving_Contact_CoreDataObject *managedObject in data) {
    if ([managedObject.bareJid isEqual:_user.jabberId]) {
       // [moc deleteObject:managedObject];**//Here i want to replace object to managed object never delete**
    }
}

0 个答案:

没有答案