Core Data
| Company type | Framework |
|---|---|
| Industry | Software development |
| Founded | 2005 |
| Founder | Apple Inc. |
| Headquarters | Cupertino, California , United States |
| Products | Object graph management and data persistence framework |
| Owner | Apple Inc. |
| Website | developer |
Core Data is an object graph and persistence framework created by Apple Inc for use on macOS and iOS platforms. Launched with Mac OS X 10.4 Tiger and iOS SDK 3.0, it allows data structured according to the relational entity–attribute model to be stored in formats such as XML, binary, or SQLite. Core Data operates by managing data through high-level objects that represent entities and their interconnections, overseeing object lifecycle, graph management, and data persistence. It communicates directly with SQLite, abstracting the underlying SQL operations from developers.
Much like how Cocoa Bindings support controller functions within a model–view–controller design pattern, Core Data handles numerous responsibilities related to the data model, including tracking changes, saving to disk, optimizing memory usage, and executing queries.
Usage
Core Data relies on a high-level data schema defined by entities, relationships, and fetch requests that retrieve entities based on specified conditions. Developers interact with data exclusively as objects without concern for storage mechanics. Controller objects built in Interface Builder can link directly to these entities, and when used alongside Cocoa bindings, the user interface can mirror the data model with minimal programming effort.
For example, when working with vCards, a developer can employ Core Data to convert vCard details into managed entities using Xcode’s data modeling tools and Interface Builder. Reading vCards into Core Data objects is accomplished via standard Objective-C or Swift code. Afterward, all manipulations are performed on these objects rather than raw vCard data. UI elements such as a Save menu option can prompt Core Data to detect modified ("dirty") objects and commit those changes to persistent storage.
Although Core Data encompasses many classes, developers typically engage mainly with the following key components:
| Class | Purpose | Primary methods |
|---|---|---|
| NSManagedObject |
|
|
| NSManagedObjectContext |
|
|
| NSManagedObjectModel |
|
|
| NSFetchRequest |
|
|
| NSPersistentStoreCoordinator |
|
|
| NSPredicate |
|
|
Storage formats
Core Data supports serialization of managed objects into XML, binary, or SQLite formats. Since the release of Mac OS X 10.5 Leopard, developers have been able to implement custom atomic store types as well. Each format presents different advantages; for instance, XML offers human readability whereas SQLite provides better memory efficiency.
This functionality is reminiscent of the original Enterprise Objects Framework (EOF), which facilitated advanced querying capabilities. However, unlike EOF, Core Data does not allow custom SQL queries because its underlying stores may not be based on SQL engines. Recently, an ODBC-backed Core Data store has been introduced within the ODBC framework.
Core Data uses standardized schemas; thanks to the Xcode Data Model file format, these schemas can be freely read from and written to. Unlike EOF, Core Data is not inherently designed for multiuser or concurrent access scenarios unless integrated with the ODBC framework.
Schema migration remains a challenging process that generally requires explicit coding efforts. When multiple developers depend on a shared data model, it is often necessary to provide version translation logic alongside updated data models whenever schema modifications occur.
History and origins
The architecture of Core Data is largely influenced by an earlier product from NeXT, known as the Enterprise Objects Framework (EOF).
EOF functioned as an object-relational mapping solution tailored for enterprise-level SQL databases such as Microsoft SQL Server and Oracle. Its primary goal was to shield developers from the complexities of database interactions by transforming relational data into object representations, thereby streamlining the development of sophisticated applications. EOF's object model facilitated document-style workflows, enabling users to modify data locally before committing all changes simultaneously.
Among EOF's distinctive features were advanced state management capabilities absent in other NeXTSTEP/OpenStep components. These included monitoring altered ("dirty") objects and maintaining an extensive Undo stack that captured reversible operations. The practical benefits of this state management led to its adoption within the Cocoa API during Apple's shift to Mac OS X.
Initially, EOF was not ported directly; it primarily served the OpenStep-era WebObjects, an application server originally developed with Objective-C. However, when Apple migrated WebObjects to Java, integrating EOF with Cocoa became more challenging, which caused frustration among developers.
A crucial realization was that EOF's object state management operated independently from relational databases. This mechanism managed object graphs beyond database contexts by automatically generating and tracking collections of objects derived from raw data—a principle that forms the foundation of Core Data.
References
- Apple Inc. (September 17, 2009). "Core Data Programming Guide". Retrieved from https://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
- Apple Inc. (September 9, 2009). "Core Data Tutorial for iPhone OS". Retrieved from https://developer.apple.com/iphone/library/documentation/DataManagement/Conceptual/iPhoneCoreData01/Introduction/Introduction.html
- Apple Inc. (2006). "EOModeler User Guide". Retrieved from https://developer.apple.com/legacy/mac/library/documentation/WebObjects/UsingEOModeler/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001018-CH201-TP1
- Jurewitz, M. & Apple Inc. (2010). "iPhone Development Videos: Working With Core Data". Retrieved from https://developer.apple.com/videos/iphone/#video-advanced-coredata
- Stevenson, S. (2005). "Core Data Class Overview". Retrieved from http://cocoadevcentral.com/articles/000086.php
- Zarra, M. S. (2009). Core Data Apple's API for Persisting Data on Mac OS X. The Pragmatic Programmers.
- LaMarche, J., & Mark, D. (2009). More iPhone 3 Development: Tackling iPhone SDK 3. Apress.
External links
- Apple Inc. (2018). "Core Data". Available at https://developer.apple.com/documentation/coredata
- Apple Inc. (2009). "Web Objects Tutorial". Accessible via https://developer.apple.com/legacy/mac/library/documentation/DeveloperTools/Conceptual/WOTutorial/Introduction/Introduction.html
- CocoaDev. (n.d.). Archived version available at https://web.archive.org/web/20080801025517/http://www.cocoadev.com/
- GitHub. "Odbc framework". Found at https://github.com/mhakman/osx-cocoa-odbc
- mFluent LLC. "View Core Data Persistence Files". Repository located at https://github.com/yepher/CoreDataUtility
- Stevenson, S. (2005). "Build A Core Data Application". Retrieved from http://cocoadevcentral.com/articles/000085.php