Core Data Features
-
Change tracking and undo support.
Core Data provides built-in management of undo and redo beyond basic text editing.
-
Relationship maintenance.
Core Data manages change propagation, including maintaining the consistency of relationships among objects.
-
Futures (faulting).
Core Data can reduce the memory overhead of your program by lazily loading objects. It also supports partially materialized futures, and copy-on-write data sharing.
-
Automatic validation of property values.
Core Data’s managed objects extend the standard key-value coding validation methods that ensure that individual values lie within acceptable ranges so that combinations of values make sense.
-
Schema migration.
Dealing with a change to your application’s schema can be difficult, in terms of both development effort and runtime resources. Core Data’s schema migration tools simplify the task of coping with schema changes, and in some cases allow you to perform extremely efficient in-place schema migration.
-
Optional integration with the application’s controller layer to support user interface synchronization.
Core Data provides the
NSFetchedResultsController
object on iOS, and integrates with Cocoa Bindings on OS X. -
Full, automatic, support for key-value coding and key-value observing.
In addition to synthesizing key-value coding and key-value observing compliant accessor methods for attributes, Core Data synthesizes the appropriate collection accessors for to-many relationships.
-
Grouping, filtering, and organizing data in memory and in the user interface.
-
Automatic support for storing objects in external data repositories.
-
Sophisticated query compilation.
Instead of writing SQL, you can create complex queries by associating an
NSPredicate
object with a fetch request.NSPredicate
provides support for basic functions, correlated subqueries, and other advanced SQL. With Core Data, it also supports proper Unicode, locale-aware searching, sorting, and regular expressions. -
Merge policies.
Core Data provides built in version tracking and optimistic locking to support automatic multi-writer conflict resolution.
Undo Management
NSManagedObjectContext *moc = ...;
[moc processPendingChanges]; // flush operations for which you want undos
[[moc undoManager] disableUndoRegistration];
// make changes for which undo operations are not to be recorded
[moc processPendingChanges]; // flush operations for which you do not want undos
[[moc undoManager] enableUndoRegistration];
Ensuring Data Is Up-to-Date
To refresh a managed object's property values, you use the managed object context methodrefreshObject:mergeChanges:
.