iOS Core Data do you have to pull out an object before you can update it?


macrumors 65816
Original poster
Sep 11, 2008
In SQL if I want to update every value in a column if its equal to x or less than X i can just put that in a query and fire it off.

UPDATE Records SET isCurrent=0 WHERE isCurrent='1'

Can I do this in Core Data (I hope so) or do I have to do a query to get every record out (as an NSManagedObject) where isCurrent=0 then iterate through setting each and every one then saving?


macrumors 601
May 10, 2010
The database structure of CoreData is private to Apple; better no messing around with direct access.
As CoreData focus on objects I think you better read them, change the values with all potential consistencies checks your code might have and commit them back.

You can also save them as bulk: one [mocontext :save] after the iteration. Should be quick enough and easy to code.

Even more if your CoreData is linked to iCloud. Changing direct will bypass all synchronization mechanisms. Not sure if relevant in your case.


Staff member
Aug 9, 2009
Pale blue comma
Core Data is fundamentally designed around object graphs.
Core Data is an object graph and persistence framework provided by Apple in the Mac OS X and iOS operating systems.
The Core Data framework provides generalized and automated solutions to common tasks associated with object life-cycle and object graph management, including persistence.
Object graph

In an object-oriented program, groups of objects form a network through their relationships with each other—either through a direct reference to another object or through a chain of intermediate references. These groups of objects are referred to as object graphs. Object graphs may be small or large, simple or complex. An array object that contains a single string object represents a small, simple object graph. A group of objects containing an application object, with references to the windows, menus and their views, and other supporting objects, may represent a large, complex object graph.

If you're not thinking of your data in terms of object graphs, how to make them, persist them, update them, etc. then it's pretty unlikely that Core Data will be a good fit with your data model.

Since your question is expressed as a specific SQL statement, rather than being expressed in terms of objects and object graphs, it suggests that your data model is a poor fit with Core Data.