Update record using Core Data in iOS

I cannot find an example of how to update an existing row of data using Core Data in iOS. Regarding SQL, I want to do something like: UPDATE device SET attr1 = 'blah', attr2 = 'blah' WHERE deviceid = '1';

I know I can do something like this: [device setValue: @ "blah" forKey: @ "attr1"];

However, how can I do this, only WHERE deviceid = '1'?

Any help is appreciated.

+5
source share
2 answers

Use the method lastObjectfor security reasons. If executeFetchRequest:error:nil returns, your program will fail:

NSManagedObject *device = [fetchedObjects lastObject];
+1
source

Core Data SQL- ... , , ObjectContext.

... [device setValue:@"blah" forKey:@"attr1"]; , - where.

, NSFetchRequest. , , Core Data. SQL WHERE, , , Core Data.

+13

All Articles