tags:

views:

72

answers:

1

Hi,

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 name 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.

+2  A: 

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
Joe Cannatti
How to get the managedObject. Like lets say I want to retrieve the managed object with id =10 then how to do that.
rkb