开发者

How to update an item in core data

I am using Core Data. I retrieve data in a NSMutable array using some NSPredicate. Now I want to update some items. Let say I have a nam开发者_如何学JAVAe string or some BOOL which I want to update. So how to do that. Like Is there any way I can update with respect to ID or something, becoz I dont get all the items from the managedObjectContext.


You assign the data to the objects. and then call

[managedObjectContext save:&error];

on each the respective context object. You can call

[managedObject managedObjectContext];

to get that items context

To get a managed object with a certain id you use NSFetchRequest and it's setPredicate method. then something like this

[request setEntity:[NSEntityDescription entityForName:@"Shirt" inManagedObjectContext:moc]];
NSArray *shirtsInDB = [moc executeFetchRequest:request error:nil];

or this method in NSManagedObjectContext

- (NSManagedObject *)objectWithID:(NSManagedObjectID *)objectID
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜