Core Data

Short description: Persistence framework provided by Apple in the macOS and iOS operating systems

Core Data

Developer(s)| Apple Inc.
Stable release|

3.2.0

Operating system| macOS, iOS, tvOS, watchOS
Type| System Utility
License| Proprietary
Website| Apple Developer Core Data Programming Guide

Core Data is an object graph and persistence framework provided by Apple in the macOS and iOS operating systems. It was introduced in Mac OS X 10.4 Tiger and iOS with iPhone SDK 3.0.[1] It allows data organized by the relational entity–attribute model to be serialized into XML, binary, or SQLite 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 management, including persistence. Core Data interfaces directly with SQLite, insulating the developer from the underlying SQL.[2]

Just as Cocoa Bindings handle many of the duties of the controller in a model–view–controller 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.

## Contents

* 1 Usage
* 2 Storage formats
* 3 History and genesis
* 4 Notes
* 5 References
* 6 External links

## 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 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 vCards. 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 from the data designer in Xcode into an interface builder window to create a GUI for their schema. They could then write standard Objective-C or 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, 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.

Name | Use | Key methods

|
|

NSManagedObject  |

* Access attributes
* A "row" of data

* -entity
* -valueForKey:
* -setValue:forKey:

NSManagedObjectContext  |

* Actions
* Changes

* -executeFetchRequest:error:
* -save

NSManagedObjectModel  |

* Structure
* Storage

* -entities
* -fetchRequestTemplateForName:
* -setFetchRequestTemplate:

forName:
NSFetchRequest  |

* Request data

* -setEntity:
* -setPredicate:
* -setFetchBatchSize:

NSPersistentStoreCoordinator  |

* Mediator
* Persisting the data

* -addPersistentStoreWithType:

configuration:URL:
options:error:

* -persistentStoreForURL:

NSPredicate  |

* Specify query

* +predicateWithFormat:
* -evaluateWithObject:

[3][2][4][5]

## Storage formats

Core Data can serialize objects into XML, binary, or SQLite for storage.[2] 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.[6]

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.[6]

Schema migration 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 product, Enterprise Objects Framework (EOF).[7]

EOF was an object-relational mapping for high-end SQL database engines such as Microsoft SQL Server and Oracle. 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/OpenStep. 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.

Initially, what was not translated was EOF itself. EOF was used primarily along with another OpenStep-era product, WebObjects, which was an application server originally based on Objective-C. At the time, Apple was in the process of porting WebObjects to the Java programming language, 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

1. ↑ Apple, "Core Data Tutorial for iPhone OS".
2. ↑ 2.0 2.1 2.2 Apple, "Core Data Programming Guide".
3. ↑ Zarra, Core Data.
4. ↑ Stevenson, "Core Data Class Overview"
5. ↑ Jurewitz, "Working With Core Data"
6. ↑ 6.0 6.1 Github, "Odbc framework"
7. ↑ Apple, "EOModeler User Guide"

## 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". Retrieved from https://developer.apple.com/documentation/coredata
* Apple Inc. (2009). "Web Objects Tutorial". Retrieved from https://developer.apple.com/legacy/mac/library/documentation/DeveloperTools/Conceptual/WOTutorial/Introduction/Introduction.html
* CocoaDev. (n.d.). Retrieved from 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 http://cocoadevcentral.com/articles/000085.php

* v
* t
* e

macOS

* History
* Architecture
* Components
* Server
* Software

Versions|

* Server 1.0 Hera
* Public Beta Kodiak
* 10.0 Cheetah
* 10.1 Puma
* 10.2 Jaguar
* 10.3 Panther
* 10.4 Tiger
* 10.5 Leopard
* 10.6 Snow Leopard
* 10.7 Lion
* 10.8 Mountain Lion
* 10.9 Mavericks
* 10.10 Yosemite
* 10.11 El Capitan
* 10.12 Sierra
* 10.13 High Sierra
* 10.14 Mojave
* 10.15 Catalina

Applications|

* App Store
* Automator
* Calculator
* Calendar
* Chess
* Contacts
* Dictionary
* DVD Player
* FaceTime
* Finder
* Game Center
* Grapher
* Home
* iTunes (history)
* Launchpad
* Mail
* Messages
* News
* Music
* Notes
* Notification Center
* Podcasts
* Photo Booth
* Photos
* Preview
* QuickTime
* Reminders
* Safari (version history)
* Stickies
* TextEdit
* Time Machine

Discontinued|

* Dashboard
* Front Row
* iChat
* iPhoto
* iSync
* Sherlock

Utilities|

* Activity Monitor
* AirPort Utility
* AppleScript Editor
* Archive Utility
* Audio MIDI Setup
* Bluetooth File Exchange
* Boot Camp
* ColorSync
* Configurator
* Console
* Crash Reporter
* DigitalColor Meter
* Directory Utility
* DiskImageMounter
* Disk Utility
* Font Book
* Grab
* Help Viewer
* Image Capture
* Installer
* Keychain Access
* Migration Assistant
* Network Utility
* ODBC Administrator
* Screen Sharing
* System Preferences
* System Information
* Terminal
* Universal Access
* VoiceOver

Discontinued|

* Software Update
* Remote Install Mac OS X

Technology and user interface|

* AirDrop
* Apple File System
* Apple menu
* Apple Push Notification service
* AppleScript
* Aqua
* Audio Units
* AVFoundation
* Bonjour
* Bundle
* CloudKit
* Cocoa
* ColorSync
* Command key
* Core Animation
* Core Audio
* Core Data
* Core Foundation
* Core Image
* Core OpenGL
* Core Text
* Core Video
* CUPS
* Cover Flow
* Darwin
* Dock
* FileVault
* Fonts
* Gatekeeper
* Grand Central Dispatch
* icns
* iCloud
* I/O Kit
* Kernel panic
* Keychain
* launchd
* Mach-O
* Menu extra
* Metal
* Mission Control
* OpenCL
* Option key
* Preference Pane
* Property list
* Quartz
* Quick Look
* Smart Folders
* Speakable items
* Spotlight
* Stacks
* System Integrity Protection
* Uniform Type Identifier
* Universal binary
* WebKit
* XNU
* XQuartz

Deprecated|

* HFS+

Discontinued|

* BootX
* Brushed metal
* Carbon
* Classic Environment
* Inkwell
* QTKit
* Rosetta
* Spaces
* Xgrid

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Core Data. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Core_Data&oldid=713509"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template