SlideShare a Scribd company logo
Core Data
By Robert Brown
@robby_brown
Basic Core Data
What is Core Data?


Intimidating
An amazing data persistence framework
Not a database
Model View Controller

 Interface
             View             Controller   Xcode
  Builder



                      Model


                    Core Data
Core Data Layers

                           Application

                        NSManagedObject

                   NSManagedObjectContext

     NSPersistentStoreCoordinator    NSManagedObjectModel

                        NSPersistentStore

      XML      SQLite      Binary    In Memory   Custom
Persistent Store


 NSPersistentStore
 Four storage types: XML (Mac only), SQLite, binary,
 and in memory
 Developers can add their own custom formats
Persistent Store Coordinator

 NSPersistentStoreCoordinator
 Façade between persistent store(s) and managed
 object context(s)
 May only have one MOM
 Not thread safe!
 lock, unlock, and tryLock methods are provided.
Persistent Store Coordinator

Managed
  Object
Contexts
 Persistent
   Store
Coordinator
Persistent
 Stores
Managed Object
Model

NSManagedObjectModel
A representation of the app’s data model
Visually built in Xcode (usually)
Commonly called a “MOM”
Managed Object
Model
Entities

 NSEntityDescription
 Entities represent objects
 Entities can have attributes such as numbers and
 strings
 Entities can have to-one and to-many relationships to
 other entities
Managed Object Context
NSManagedObjectContext
The “scratch pad” of you application
Changes aren’t saved until calling save:
Always check for errors
Create a new context for each thread
Commonly called a “MOC”
Managed Object

NSManagedObject
Superclass of all managed objects
Properties can be accessed via KVC/KVO
Don’t pass managed objects between threads, pass
their objectID instead
Fetch Requests


NSFetchRequest
Used to retrieve objects from the store
Uses an NSPredicate for the query
Advanced Core Data
Fetch Request Efficiency                        Jedi
                                               Level




Smaller batches may be requested for greater
efficiency (SQLite only)
Objects may be returned as faults
SUBQUERY can be used to have the database do the
work instead of Core Data
Fetch Request Templates                       Jedi
                                              Level




Common fetch requests can be stored as a template
For example, all persons with a given name
Use fetchRequestFromTemplateWithName:
substitutionVariables:
Transient Attributes                                   Jedi
                                                       Level




 Attributes in the local object but not in the store
 Typically used for convenience
 Example: fullName = “firstName lastName”
 Requires adding code to generated objects
Delete Rules                                Jedi
                                            Level




Deny: Don’t allow if some relation exists
Nullify: Set relationship to nil
Cascade: Delete related objects
No Action: Do nothing, I want to cleanup
Versioning and Migration                           Jedi
                                                   Level




 MOM is your contract with Core Data
 If you change your model you must migrate the data to
 match the new data model
 Use a custom mapping model for changes
 Lightweight migration automatically makes minor
 changes (Snow Leopard/iOS 3.0+)
Configurations                                             Jedi
                                                          Level




A persistent store coordinator may only have one MOM
One MOM may have many configurations
A configuration is a subset of entities
Typically used to store different entities in different
stores using one store coordinator
Demo
Resources


Apple Documentation
Core Data: Apple’s API for Persisting Data on Mac OS
X by Marcus S. Zarra
https://developer.apple.com/videos/wwdc/2010/
Questions?

More Related Content

What's hot

Strategy Pattern
Strategy PatternStrategy Pattern
Strategy PatternGuo Albert
 
String handling in_java
String handling in_javaString handling in_java
String handling in_java
774474
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
Lokesh Kakkar Mobile No. 814-614-5674
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
shashi shekhar
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
 
Data mining
Data mining Data mining
Data mining
sayalipatil528
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
之宇 趙
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
Anton Keks
 
Automated Negotiation
Automated NegotiationAutomated Negotiation
Automated Negotiation
Kyoto University
 
Market basket analysis
Market basket analysisMarket basket analysis
Market basket analysis
tsering choezom
 
Introduction to dataset
Introduction to datasetIntroduction to dataset
Introduction to dataset
datamantra
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
Darshan Ambhaikar
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns pptAman Jain
 
Data mining
Data miningData mining
Data mining
Birju Tank
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
Shahriar Hyder
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
Hüseyin Ergin
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
Anjan Kumar Bollam
 
Federated Learning
Federated LearningFederated Learning
Federated Learning
DataWorks Summit
 

What's hot (20)

Strategy Pattern
Strategy PatternStrategy Pattern
Strategy Pattern
 
String handling in_java
String handling in_javaString handling in_java
String handling in_java
 
Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674Core java complete notes - Contact at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Data mining
Data mining Data mining
Data mining
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Automated Negotiation
Automated NegotiationAutomated Negotiation
Automated Negotiation
 
Market basket analysis
Market basket analysisMarket basket analysis
Market basket analysis
 
Introduction to dataset
Introduction to datasetIntroduction to dataset
Introduction to dataset
 
Machine Learning
Machine LearningMachine Learning
Machine Learning
 
Design patterns ppt
Design patterns pptDesign patterns ppt
Design patterns ppt
 
Data mining
Data miningData mining
Data mining
 
Command Design Pattern
Command Design PatternCommand Design Pattern
Command Design Pattern
 
Chain of Responsibility Pattern
Chain of Responsibility PatternChain of Responsibility Pattern
Chain of Responsibility Pattern
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Federated Learning
Federated LearningFederated Learning
Federated Learning
 

Similar to Core Data

Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
Rajiv Gupta
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
David McCarter
 
Mac/iOS Design Patterns
Mac/iOS Design PatternsMac/iOS Design Patterns
Mac/iOS Design Patterns
Robert Brown
 
Intro to Core Data
Intro to Core DataIntro to Core Data
Intro to Core Data
Make School
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
Julie Lerman
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Ef code first
Ef code firstEf code first
Ef code first
ZealousysDev
 
MVVM
MVVMMVVM
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
Luis Goldster
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in Smalltalk
ESUG
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1b_kathir
 
EnScript Workshop
EnScript WorkshopEnScript Workshop
EnScript Workshop
Mark Morgan, CCE, EnCE
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
James Johnson
 
Hibernate
HibernateHibernate
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfit
allanh0526
 
Introduction to odbms
Introduction to odbmsIntroduction to odbms
Introduction to odbms
ajay pashankar
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
aminmesbahi
 

Similar to Core Data (20)

Hibernate 3
Hibernate 3Hibernate 3
Hibernate 3
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Mac/iOS Design Patterns
Mac/iOS Design PatternsMac/iOS Design Patterns
Mac/iOS Design Patterns
 
Intro to Core Data
Intro to Core DataIntro to Core Data
Intro to Core Data
 
Entity Framework Today (May 2012)
Entity Framework Today (May 2012)Entity Framework Today (May 2012)
Entity Framework Today (May 2012)
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
Free Hibernate Tutorial | VirtualNuggets
Free Hibernate Tutorial  | VirtualNuggetsFree Hibernate Tutorial  | VirtualNuggets
Free Hibernate Tutorial | VirtualNuggets
 
Ef code first
Ef code firstEf code first
Ef code first
 
MVVM
MVVMMVVM
MVVM
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in Smalltalk
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1
 
EnScript Workshop
EnScript WorkshopEnScript Workshop
EnScript Workshop
 
La sql
La sqlLa sql
La sql
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 
Hibernate
HibernateHibernate
Hibernate
 
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfit
 
Introduction to odbms
Introduction to odbmsIntroduction to odbms
Introduction to odbms
 
.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13.NET Core, ASP.NET Core Course, Session 13
.NET Core, ASP.NET Core Course, Session 13
 

More from Robert Brown

High level concurrency
High level concurrencyHigh level concurrency
High level concurrency
Robert Brown
 
Data Source Combinators
Data Source CombinatorsData Source Combinators
Data Source Combinators
Robert Brown
 
Elixir
ElixirElixir
Elixir
Robert Brown
 
Reactive Cocoa
Reactive CocoaReactive Cocoa
Reactive Cocoa
Robert Brown
 
UIKit Dynamics
UIKit DynamicsUIKit Dynamics
UIKit Dynamics
Robert Brown
 
iOS State Preservation and Restoration
iOS State Preservation and RestorationiOS State Preservation and Restoration
iOS State Preservation and Restoration
Robert Brown
 
Pragmatic blocks
Pragmatic blocksPragmatic blocks
Pragmatic blocks
Robert Brown
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
Robert Brown
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design Patterns
Robert Brown
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
Robert Brown
 
Quick Look for iOS
Quick Look for iOSQuick Look for iOS
Quick Look for iOS
Robert Brown
 

More from Robert Brown (12)

High level concurrency
High level concurrencyHigh level concurrency
High level concurrency
 
Data Source Combinators
Data Source CombinatorsData Source Combinators
Data Source Combinators
 
Elixir
ElixirElixir
Elixir
 
Reactive Cocoa
Reactive CocoaReactive Cocoa
Reactive Cocoa
 
UIKit Dynamics
UIKit DynamicsUIKit Dynamics
UIKit Dynamics
 
iOS State Preservation and Restoration
iOS State Preservation and RestorationiOS State Preservation and Restoration
iOS State Preservation and Restoration
 
Anti-Patterns
Anti-PatternsAnti-Patterns
Anti-Patterns
 
Pragmatic blocks
Pragmatic blocksPragmatic blocks
Pragmatic blocks
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference Counting
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design Patterns
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Quick Look for iOS
Quick Look for iOSQuick Look for iOS
Quick Look for iOS
 

Recently uploaded

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
QADay
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Ransomware Mallox [EN].pdf
Ransomware         Mallox       [EN].pdfRansomware         Mallox       [EN].pdf
Ransomware Mallox [EN].pdf
Overkill Security
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...КАТЕРИНА АБЗЯТОВА  «Ефективне планування тестування  ключові аспекти та практ...
КАТЕРИНА АБЗЯТОВА «Ефективне планування тестування ключові аспекти та практ...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Ransomware Mallox [EN].pdf
Ransomware         Mallox       [EN].pdfRansomware         Mallox       [EN].pdf
Ransomware Mallox [EN].pdf
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Core Data

  • 1. Core Data By Robert Brown @robby_brown
  • 3. What is Core Data? Intimidating An amazing data persistence framework Not a database
  • 4. Model View Controller Interface View Controller Xcode Builder Model Core Data
  • 5. Core Data Layers Application NSManagedObject NSManagedObjectContext NSPersistentStoreCoordinator NSManagedObjectModel NSPersistentStore XML SQLite Binary In Memory Custom
  • 6. Persistent Store NSPersistentStore Four storage types: XML (Mac only), SQLite, binary, and in memory Developers can add their own custom formats
  • 7. Persistent Store Coordinator NSPersistentStoreCoordinator Façade between persistent store(s) and managed object context(s) May only have one MOM Not thread safe! lock, unlock, and tryLock methods are provided.
  • 8. Persistent Store Coordinator Managed Object Contexts Persistent Store Coordinator Persistent Stores
  • 9. Managed Object Model NSManagedObjectModel A representation of the app’s data model Visually built in Xcode (usually) Commonly called a “MOM”
  • 11. Entities NSEntityDescription Entities represent objects Entities can have attributes such as numbers and strings Entities can have to-one and to-many relationships to other entities
  • 12. Managed Object Context NSManagedObjectContext The “scratch pad” of you application Changes aren’t saved until calling save: Always check for errors Create a new context for each thread Commonly called a “MOC”
  • 13. Managed Object NSManagedObject Superclass of all managed objects Properties can be accessed via KVC/KVO Don’t pass managed objects between threads, pass their objectID instead
  • 14. Fetch Requests NSFetchRequest Used to retrieve objects from the store Uses an NSPredicate for the query
  • 16. Fetch Request Efficiency Jedi Level Smaller batches may be requested for greater efficiency (SQLite only) Objects may be returned as faults SUBQUERY can be used to have the database do the work instead of Core Data
  • 17. Fetch Request Templates Jedi Level Common fetch requests can be stored as a template For example, all persons with a given name Use fetchRequestFromTemplateWithName: substitutionVariables:
  • 18. Transient Attributes Jedi Level Attributes in the local object but not in the store Typically used for convenience Example: fullName = “firstName lastName” Requires adding code to generated objects
  • 19. Delete Rules Jedi Level Deny: Don’t allow if some relation exists Nullify: Set relationship to nil Cascade: Delete related objects No Action: Do nothing, I want to cleanup
  • 20. Versioning and Migration Jedi Level MOM is your contract with Core Data If you change your model you must migrate the data to match the new data model Use a custom mapping model for changes Lightweight migration automatically makes minor changes (Snow Leopard/iOS 3.0+)
  • 21. Configurations Jedi Level A persistent store coordinator may only have one MOM One MOM may have many configurations A configuration is a subset of entities Typically used to store different entities in different stores using one store coordinator
  • 22. Demo
  • 23. Resources Apple Documentation Core Data: Apple’s API for Persisting Data on Mac OS X by Marcus S. Zarra https://developer.apple.com/videos/wwdc/2010/

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n