Core Data is an
object graph
In computer science, 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 ...
and
persistence framework
A persistence framework is middleware that assists in the storage and retrieval of information between applications and databases, especially relational databases. It acts as a layer of abstraction for persisted data, bridging conceptual and techni ...
provided by
Apple
An apple is an edible fruit produced by an apple tree (''Malus domestica''). Apple fruit tree, trees are agriculture, cultivated worldwide and are the most widely grown species in the genus ''Malus''. The tree originated in Central Asia, wh ...
in the
macOS
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
and
iOS
iOS (formerly iPhone OS) is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that powers many of the company's mobile devices, including the iPhone; the term also includes ...
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
s. It was introduced in
Mac OS X 10.4 Tiger
Mac OS X Tiger (version 10.4) is the 5th major release of macOS, Apple's desktop and server operating system for Mac computers. Tiger was released to the public on April 29, 2005 for US$129.95 as the successor to Mac OS X 10.3 Panther. Some of ...
and
iOS
iOS (formerly iPhone OS) is a mobile operating system created and developed by Apple Inc. exclusively for its hardware. It is the operating system that powers many of the company's mobile devices, including the iPhone; the term also includes ...
with iPhone SDK 3.0.
[Apple, "Core Data Tutorial for iPhone OS".] It allows data organized by the
relational entity–attribute model to be
serialized into
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
,
binary
Binary may refer to:
Science and technology Mathematics
* Binary number, a representation of numbers using only two digits (0 and 1)
* Binary function, a function that takes two arguments
* Binary operation, a mathematical operation that t ...
, or
SQLite
SQLite (, ) is a database engine written in the C programming language. It is not a standalone app; rather, it is a library that software developers embed in their apps. As such, it belongs to the family of embedded databases. It is the most ...
stores. The data can be manipulated using higher level objects representing entities and their relationships. Core Data manages the serialized version, providing
object lifecycle and
object graph
In computer science, 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 ...
management, including
persistence. Core Data interfaces directly with
SQLite
SQLite (, ) is a database engine written in the C programming language. It is not a standalone app; rather, it is a library that software developers embed in their apps. As such, it belongs to the family of embedded databases. It is the most ...
, insulating the developer from the underlying
SQL.
[Apple, "Core Data Programming Guide".]
Just as
Cocoa Bindings handle many of the duties of the controller in a
model–view–controller
Model–view–controller (MVC) is a software architectural pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements. This is done to separate internal representations of infor ...
design, Core Data handles many of the duties of the data model. Among other tasks, it handles change management, serializing to disk, memory footprint minimization and queries against the data.
Usage
Core Data describes data with a high level data model expressed in terms of entities and their relationships plus fetch requests that retrieve entities meeting specific criteria. Code can retrieve and manipulate this data on a purely object level without having to worry about the details of storage and retrieval. The controller objects available in
Interface Builder
Interface Builder is a software development application for Apple Inc., Apple's macOS operating system. It is part of Xcode (formerly Project Builder), the Apple Developer developer's toolset. Interface Builder allows Cocoa (API), Cocoa and Car ...
can retrieve and manipulate these entities directly. When combined with Cocoa bindings the UI can display many components of the data model without needing background code.
For example: a developer might be writing a program to handle
vCard
vCard, also known as VCF (Virtual Contact File), is a file format standard for electronic business cards. vCards can be attached to e-mail messages, sent via Multimedia Messaging Service (MMS), on the World Wide Web, instant messaging, NFC or ...
s. In order to manage these, the author intends to read the vCards into objects, and then store them in a single larger XML file. Using Core Data the developer would drag their
schema
The word schema comes from the Greek word ('), which means ''shape'', or more generally, ''plan''. The plural is ('). In English, both ''schemas'' and ''schemata'' are used as plural forms.
Schema may refer to:
Science and technology
* SCHEMA ...
from the data designer in
Xcode
Xcode is Apple's integrated development environment (IDE) for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, and tvOS. It was initially released in late 2003; the latest stable release is version 14.2, released on December 13, ...
into an interface builder window to create a GUI for their schema. They could then write standard
Objective-C
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
or
Swift
Swift or SWIFT most commonly refers to:
* SWIFT, an international organization facilitating transactions between banks
** SWIFT code
* Swift (programming language)
* Swift (bird), a family of birds
It may also refer to:
Organizations
* SWIFT, ...
code to read vCard files and put the data into Core Data managed entities. From that point on the author's code manipulates these Core Data objects, rather than the underlying vCards. Connecting the
Save
menu item to the appropriate method in the controller object will direct the controller to examine the object stack, determine which objects are
dirty
Dirt is an unclean matter, especially when in contact with a person's clothes, skin, or possessions. In such cases, they are said to become dirty.
Common types of dirt include:
* Debris: scattered pieces of waste or remains
* Dust: a genera ...
, and then re-write a Core Data document file with these changes.
Core Data is organized into a large hierarchy of classes, though interaction is only prevalent with a small set of them.
[Zarra, ''Core Data''.][Stevenson, "Core Data Class Overview"][Jurewitz, "Working With Core Data"]
Storage formats
Core Data can serialize objects into XML, binary, or SQLite
SQLite (, ) is a database engine written in the C programming language. It is not a standalone app; rather, it is a library that software developers embed in their apps. As such, it belongs to the family of embedded databases. It is the most ...
for storage.[ With the release of ]Mac OS X 10.5 Leopard
Mac OS X Leopard (version 10.5) is the sixth major release of macOS, Apple's desktop and server operating system for Macintosh computers. Leopard was released on October 26, 2007 as the successor of Mac OS X 10.4 Tiger, and is available in two ...
, developers can also create their own custom atomic store types. Each method carries advantages and disadvantages, such as being human readable (XML) or more memory efficient (SQLite).
This portion of Core Data is similar to the original Enterprise Objects Framework The Enterprise Objects Framework, or more commonly simply EOF, was introduced by NeXT in 1994 as a pioneering object-relational mapping product for its NeXTSTEP and OpenStep development platforms. EOF abstracts the process of interacting with a re ...
(EOF) system, in that one can write fairly sophisticated queries. Unlike EOF, it is not possible to write your own SQL, as the underlying store may not be SQL-based. Recently, Core Data store for ODBC has been made available in ODBC framework
In computing, Open Database Connectivity (ODBC) is a standard application programming interface (API) for accessing database management systems (DBMS). The designers of ODBC aimed to make it independent of database systems and operating systems. An ...
.[Github, "Odbc framework"]
Core Data schemas are standardized. If you have the Xcode Data Model file, you can read and write files in that format freely. Unlike EOF, though, Core Data is not currently designed for multiuser or simultaneous access unless you use ODBC framework.[Github, "Odbc framework"]
Schema migration
In software engineering, a schema migration (also database migration, database change management) refers to the management of version-controlled, incremental and reversible changes to relational database schemas. A schema migration is performe ...
is also non-trivial, almost always requiring code. If other developers have access to and depend upon your data model, you may need to provide version translation code in addition to a new data model if your schema changes.
History and genesis
Core Data owes much of its design to an earlier NeXT
Next may refer to:
Arts and entertainment Film
* ''Next'' (1990 film), an animated short about William Shakespeare
* ''Next'' (2007 film), a sci-fi film starring Nicolas Cage
* '' Next: A Primer on Urban Painting'', a 2005 documentary film
Lit ...
product, Enterprise Objects Framework The Enterprise Objects Framework, or more commonly simply EOF, was introduced by NeXT in 1994 as a pioneering object-relational mapping product for its NeXTSTEP and OpenStep development platforms. EOF abstracts the process of interacting with a re ...
(EOF).[Apple, "EOModeler User Guide"]
EOF was an object-relational mapping for high-end SQL database engines such as Microsoft SQL Server
Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications—which ma ...
and Oracle
An oracle is a person or agency considered to provide wise and insightful counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. As such, it is a form of divination.
Description
The word '' ...
. EOF's purpose was twofold: first, to connect to the database engine and hide the implementation details; second, to read the data out of the relational format and translate that into a set of objects. Developers typically interacted only with the objects, which simplified development of complex programs, at the cost of some setup to map the data to the objects. The EOF object model was deliberately designed to make the resulting programs work in a document-like fashion; the user could edit the data locally in memory, and then write out all changes with a single Save command.
Throughout its history, EOF contained a number of bits of useful code that were not otherwise available under NeXTSTEP
NeXTSTEP is a discontinued object-oriented, multitasking operating system based on the Mach kernel and the UNIX-derived BSD. It was developed by NeXT Computer in the late 1980s and early 1990s and was initially used for its range of proprieta ...
/OpenStep
OpenStep is a defunct object-oriented application programming interface (API) specification for a legacy object-oriented operating system, with the basic goal of offering a NeXTSTEP-like environment on non-NeXTSTEP operating systems. OpenStep was ...
. For instance, EOF required the ability to track which objects were dirty so the system could later write them out. This was presented to the developer not only as a document-like system, but also in the form of an unlimited Undo command stack, with each command applied to the data represented as an undoable action. Many developers complained that this state management code was far too useful to be isolated in EOF, and it was later moved into the Cocoa API
Cocoa is Apple's native object-oriented application programming interface (API) for its desktop operating system macOS.
Cocoa consists of the Foundation Kit, Application Kit, and Core Data frameworks, as included by the Cocoa.h header file, and ...
during the transition to Mac OS X
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac (computer), Mac computers. Within the market of ...
.
Initially, what was not translated was EOF itself. EOF was used primarily along with another OpenStep-era product, WebObjects
WebObjects was a Java web application server and a server-based web application framework originally developed by NeXT Software, Inc.
WebObject's hallmark features are its object-orientation, database connectivity, and prototyping tools. Ap ...
, which was an application server
An application server is a server that hosts applications or software that delivers a business application through a communication protocol.
An application server framework is a service layer model. It includes software components available to a ...
originally based on Objective-C
Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTS ...
. At the time, Apple was in the process of porting WebObjects to the Java programming language
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run anywh ...
, and as part of this conversion, EOF became much more difficult to use from Cocoa. Once again, there was considerable complaining among 3rd party developers.
One critical realization is that the object state management system in EOF did not really have anything to do with relational databases. The same code could be, and was, used by developers to manage graphs of other objects as well. In this role, the really useful parts of EOF were those that automatically built the object sets from the raw data, and then tracked them. It is this concept that forms the basis of Core Data.
Notes
References
* Apple Inc. (September 17, 2009). "Core Data Programming Guide". Retrieved fro
https://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
* Apple Inc. (September 9, 2009). "Core Data Tutorial for iPhone OS". Retrieved fro
* 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 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 fro
https://developer.apple.com/videos/iphone/#video-advanced-coredata
* Stevenson, S. (2005). "Core Data Class Overview". Retrieved fro
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". Retrieved fro
https://developer.apple.com/documentation/coredata
* Apple Inc. (2009). "Web Objects Tutorial". Retrieved fro
* CocoaDev. (n.d.). Retrieved from ttps://web.archive.org/web/20080801025517/http://www.cocoadev.com/ https://web.archive.org/web/20080801025517/http://www.cocoadev.com/* GitHub. "Odbc framework". https://github.com/mhakman/osx-cocoa-odbc
* mFluent LLC. "View Core Data Persistence Files". https://github.com/yepher/CoreDataUtility
* Stevenson, S. (2005). "Build A Core Data Application". Retrieved fro
http://cocoadevcentral.com/articles/000085.php
{{OS X
macOS APIs
Data modeling
Data management software
Persistence
Objective-C
NeXT