SlideShare a Scribd company logo
1 of 24
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

Digital Libraries
Digital LibrariesDigital Libraries
Digital LibrariesJack Eapen
 
Information retrieval system
Information retrieval systemInformation retrieval system
Information retrieval systemLeslie Vargas
 
Hardware and Software Requirements for Koha
Hardware and Software Requirements for KohaHardware and Software Requirements for Koha
Hardware and Software Requirements for KohaAnil Mishra
 
Library automation software
Library automation softwareLibrary automation software
Library automation softwareJancypriya M
 
Greenstone Digital Library
Greenstone Digital LibraryGreenstone Digital Library
Greenstone Digital LibraryImran Mansuri
 
Digital library software
Digital library softwareDigital library software
Digital library softwareavid
 
Greenstone Digital Library Software
Greenstone Digital Library SoftwareGreenstone Digital Library Software
Greenstone Digital Library SoftwareMINTUMATHEW8
 
Ontology and Ontology Libraries: a Critical Study
Ontology and Ontology Libraries: a Critical StudyOntology and Ontology Libraries: a Critical Study
Ontology and Ontology Libraries: a Critical StudyDebashisnaskar
 
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.`Shweta Bhavsar
 
eprints digital library software
eprints digital library softwareeprints digital library software
eprints digital library softwaresonia naomi bandao
 
Z39.50: Information Retrieval protocol ppt
Z39.50: Information Retrieval protocol pptZ39.50: Information Retrieval protocol ppt
Z39.50: Information Retrieval protocol pptSUNILKUMARSINGH
 
Current and emerging trends in library services
Current and emerging trends in library servicesCurrent and emerging trends in library services
Current and emerging trends in library servicesNikesh Narayanan
 

What's hot (20)

Webometrics
WebometricsWebometrics
Webometrics
 
Digital Libraries
Digital LibrariesDigital Libraries
Digital Libraries
 
Information retrieval system
Information retrieval systemInformation retrieval system
Information retrieval system
 
FRBR model by Gaurav Boudh
FRBR model by Gaurav BoudhFRBR model by Gaurav Boudh
FRBR model by Gaurav Boudh
 
Open source Library Management Systems
Open source Library Management SystemsOpen source Library Management Systems
Open source Library Management Systems
 
Digital library
 Digital library Digital library
Digital library
 
Hardware and Software Requirements for Koha
Hardware and Software Requirements for KohaHardware and Software Requirements for Koha
Hardware and Software Requirements for Koha
 
Library automation software
Library automation softwareLibrary automation software
Library automation software
 
Greenstone Digital Library
Greenstone Digital LibraryGreenstone Digital Library
Greenstone Digital Library
 
Importance of Database in Library
Importance of Database in LibraryImportance of Database in Library
Importance of Database in Library
 
Microforms
MicroformsMicroforms
Microforms
 
Digital library software
Digital library softwareDigital library software
Digital library software
 
Greenstone Digital Library Software
Greenstone Digital Library SoftwareGreenstone Digital Library Software
Greenstone Digital Library Software
 
Ontology and Ontology Libraries: a Critical Study
Ontology and Ontology Libraries: a Critical StudyOntology and Ontology Libraries: a Critical Study
Ontology and Ontology Libraries: a Critical Study
 
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.
WHAT IS A DIGITAL LIBRARY? EXPLAIN NDLI AND ITS CONTRIBUTION.
 
eprints digital library software
eprints digital library softwareeprints digital library software
eprints digital library software
 
New techniques and tools in the library
New techniques and tools in the libraryNew techniques and tools in the library
New techniques and tools in the library
 
Metadata harvesting Tools
Metadata harvesting ToolsMetadata harvesting Tools
Metadata harvesting Tools
 
Z39.50: Information Retrieval protocol ppt
Z39.50: Information Retrieval protocol pptZ39.50: Information Retrieval protocol ppt
Z39.50: Information Retrieval protocol ppt
 
Current and emerging trends in library services
Current and emerging trends in library servicesCurrent and emerging trends in library services
Current and emerging trends in library services
 

Similar to Core Data

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 PatternsRobert Brown
 
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 | VirtualNuggetsVirtual Nuggets
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworksLuis Goldster
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkESUG
 
Hibernate Session 1
Hibernate Session 1Hibernate Session 1
Hibernate Session 1b_kathir
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code FirstJames Johnson
 
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfitallanh0526
 
.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 13aminmesbahi
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2Eric Nelson
 

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
 
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
 
Entity Framework v1 and v2
Entity Framework v1 and v2Entity Framework v1 and v2
Entity Framework v1 and v2
 

More from Robert Brown

High level concurrency
High level concurrencyHigh level concurrency
High level concurrencyRobert Brown
 
Data Source Combinators
Data Source CombinatorsData Source Combinators
Data Source CombinatorsRobert Brown
 
iOS State Preservation and Restoration
iOS State Preservation and RestorationiOS State Preservation and Restoration
iOS State Preservation and RestorationRobert Brown
 
Automatic Reference Counting
Automatic Reference CountingAutomatic Reference Counting
Automatic Reference CountingRobert Brown
 
Grand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsGrand Central Dispatch Design Patterns
Grand Central Dispatch Design PatternsRobert Brown
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central DispatchRobert Brown
 
Quick Look for iOS
Quick Look for iOSQuick Look for iOS
Quick Look for iOSRobert 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

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 

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