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
Persistence or Persist may refer to:
Math and computers
* Image persistence, in LCD monitors
* Persistence (computer science), the characteristic of data that outlives the execution of the program that created it
* Persistence of a number, a ma ...
provided by
Apple
An apple is a round, edible fruit produced by an apple tree (''Malus'' spp.). Fruit trees of the orchard or domestic apple (''Malus domestica''), the most widely grown in the genus, are agriculture, cultivated worldwide. The tree originated ...
in the
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
and
iOS
Ios, Io or Nio (, ; ; locally Nios, Νιός) is a Greek island in the Cyclades group in the Aegean Sea. Ios is a hilly island with cliffs down to the sea on most sides. It is situated halfway between Naxos and Santorini. It is about long an ...
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
s. It was introduced in
Mac OS X 10.4 Tiger and
iOS
Ios, Io or Nio (, ; ; locally Nios, Νιός) is a Greek island in the Cyclades group in the Aegean Sea. Ios is a hilly island with cliffs down to the sea on most sides. It is situated halfway between Naxos and Santorini. It is about long an ...
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 data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
,
binary
Binary may refer to:
Science and technology Mathematics
* Binary number, a representation of numbers using only two values (0 and 1) for each digit
* Binary function, a function that takes two arguments
* Binary operation, a mathematical op ...
, or
SQLite
SQLite ( "S-Q-L-ite", "sequel-ite") is a free and open-source relational 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 ...
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
Persistence or Persist may refer to:
Math and computers
* Image persistence, in LCD monitors
* Persistence (computer science), the characteristic of data that outlives the execution of the program that created it
* Persistence of a number, a ma ...
. Core Data interfaces directly with
SQLite
SQLite ( "S-Q-L-ite", "sequel-ite") is a free and open-source relational 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 ...
, insulating the developer from the underlying
SQL
Structured Query Language (SQL) (pronounced ''S-Q-L''; or alternatively as "sequel")
is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling s ...
.
[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 divides the related program logic into three interconnected elements. These elements are:
* the model, the internal representat ...
design, Core Data handles many of the duties of the data model. Among other tasks, it handles change management, serializing to disk,
memory footprint
Memory footprint refers to the amount of main memory that a program uses or references while running.
The word footprint generally refers to the extent of physical dimensions that an object occupies, giving a sense of its size. In computing, t ...
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's macOS operating system. It is part of Xcode (formerly Project Builder), the Apple Developer developer's toolset. Interface Builder allows Cocoa and Carbon developers to crea ...
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, N ...
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
Schema may refer to:
Science and technology
* SCHEMA (bioinformatics), an algorithm used in protein engineering
* Schema (genetic algorithms), a set of programs or bit strings that have some genotypic similarity
* Schema.org, a web markup vocab ...
from the data designer in
Xcode
Xcode is a suite of developer tools for building apps on Apple devices. It includes an integrated development environment (IDE) of the same name for macOS, used to develop software for macOS, iOS, iPadOS, watchOS, tvOS, and visionOS. It w ...
into an interface builder window to create a GUI for their schema. They could then write standard
Objective-C
Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style message passing (messaging) to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was ...
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
* SWIF ...
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 any matter considered unclean, 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
* Du ...
, 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.
Sources:
[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 ( "S-Q-L-ite", "sequel-ite") is a free and open-source relational 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 ...
for storage.[ With the release of Mac OS X 10.5 Leopard, 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 (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.][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 sometimes reversible changes to relational database schemas. A schema migration i ...
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, Inc. (later NeXT Computer, Inc. and NeXT Software, Inc.) was an American technology company headquartered in Redwood City, California that specialized in computer workstations for higher education and business markets, and later develope ...
product, Enterprise Objects Framework (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 proprietary relational database management system developed by Microsoft using Structured Query Language (SQL, often pronounced "sequel"). As a database server, it is a software product with the primary function of ...
and Oracle
An oracle is a person or thing considered to provide insight, wise counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. If done through occultic means, it is a form of divination.
Descript ...
. 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, founded by Steve Jobs, in the late 1980s and early 1990s and was initially used for its ...
/OpenStep
OpenStep is an object-oriented application programming interface (API) specification developed by NeXT. It provides a framework for building graphical user interfaces (GUIs) and developing software applications. OpenStep was designed to be plat ...
. 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 during the transition to Mac OS X
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
.
Initially, what was not translated was EOF itself. EOF was used primarily along with another OpenStep-era product, WebObjects
WebObjects is a discontinued 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 prototy ...
, 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. For a typical web application, the application server sits behind the web servers.
An application ser ...
originally based on Objective-C
Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style message passing (messaging) to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was ...
. At the time, Apple was in the process of porting WebObjects to the Java programming language
Java is a high-level, general-purpose, memory-safe, object-oriented programming language. It is intended to let programmers ''write once, run anywhere'' ( WORA), meaning that compiled Java code can run on all platforms that support Jav ...
, 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 from
* 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 from
{{OS X
macOS APIs
Data modeling
Data management software
Persistence
Objective-C
NeXT