1

我想知道如何更新 CoreData 中的一行?每次我更新一行时,都会添加一个新行。

Project *saveProj = [self getProjectByFilterCriteria:predicate];

if (saveProj) {//based on predicate a single project object fetched.
    Project
    *obj = [NSEntityDescription insertNewObjectForEntityForName:@"Project"
                                         inManagedObjectContext:[[AppManager sharedInstance] uiManagedObjectContext]];
     obj =saveProj;//then saving stuffs goes here down `

任何指针?

4

2 回答 2

2

嗯,你在打电话

insertNewObjectForEntityForName

如果您不想插入新项目,请不要调用该方法。只需修改您想要的对象,然后保存即可

if (saveProj) {
    saveProj.blabla = blabla
}
于 2013-09-10T12:35:27.270 回答
0

在核心数据链接中使用谓词做更新操作:https ://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/predicates.html#//apple_ref/doc/uid/TP40001798-SW1

于 2013-09-10T12:46:15.603 回答