SlideShare a Scribd company logo
Introduction to
   Core Data
    Daniel Tull
Sky+             Little Spender




       Weather Maps               Fourgy
Core Data Stack




NSManagedObjectModel
Managed Object Model
Attributes
NSNumber
NSString         Transformable
BOOL             You put in code to
                 transform the
NSDate
                 object or value into
NSData           a compatible type.
Transformable
Relationships

Properties that reference other objects
Can be to-one or to-many (NSSet - unordered)
Can (and should) have inverses, which are worked
out by Core Data when you set the other property
Delete rule ensures propagation
Relationships
                                        DTAlbum
                                          Attributes
                       DTArtist       name
  DTGenre               Attributes    discCount
    Attributes      name              trackCount
name                  Relationships     Relationships
  Relationships     albums            artist
artists             genres            composers
songs               songs             songs
Core Data Stack
 NSManagedObjectContext




NSPersistentStoreCoordinator   NSPersistentStore




  NSManagedObjectModel
Create and Save Objects
DTSong *song = [NSEntityDescription
                     insertNewObjectForEntityForName:@“DTSong”
                              inManagedObjectContext:managedObjectContext];

DTArtist *artist = [NSEntityDescription
                     insertNewObjectForEntityForName:@“DTArtist”
                              inManagedObjectContext:managedObjectContext];

artist.name = @“Moby”;

song.title = @“Porcelain”;

song.artist = artist;

   •••

NSError *error = nil;
[managedObjectContext save:&error];
Create and Save Objects
 NSManagedObjectContext
   DTArtist
  DTSong




NSPersistentStoreCoordinator   NSPersistentStore




  NSManagedObjectModel
Fetching Objects

          All songs by “La Roux” sorted by title.


Entity         DTSong


Predicate      @“artist.name == %@”, @“La Roux”


Sorting        @“title”
Fetching Objects

Fetch all playlists which contain more than an hour of music.


   Entity       DTPlaylist


   Predicate    @“@sum.songs.duration > 3600”


   Sorting      @“name”
Fetching Objects
NSEntityDescription *entity = [NSEntityDescription
                                       entityForName:@“DTSong”
                              inManagedObjectContext:managedObjectContext];

NSPredicate *predicate = [NSPredicate
                     predicateWithFormat:@“artist.name == %@”, @“La Roux”];

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
                                       initWithKey:@“title” ascending:YES];

NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
[request setPredicate:predicate];
[request setSortDescriptors:sortDescriptors];

NSArray *fetchResult = [managedObjectContext executeFetchRequest:request
                                                           error:&error];
Fetching Objects
 NSManagedObjectContext           NSFetchRequest
   DTArtist          DTSong
                     DTSong
  DTSong             DTSong




NSPersistentStoreCoordinator   NSPersistentStore



                                    DTSong
  NSManagedObjectModel              DTSong
                                    DTSong
Performance: Faults
Faults are placeholders for related objects, which
mean you don’t use memory on unwanted objects.


                            DTSong
                             DTSong
      DTArtist                DTSong
                               DTSong
                                DTSong
Performance: Batching
                      DTArtist
                      DTArtist
Batching allows
you to bring only a   DTArtist
subset of objects     DTArtist
into memory.
                      DTArtist
                      DTArtist
Demo
DTMusicModel




hg.danieltull.co.uk/dtmusicmodel
DTGridView                DTSwapView




       hg.danieltull.co.uk/dtkit
Thank You
dt@danieltull.co.uk




hg.danieltull.co.uk

More Related Content

What's hot (20)

PDF
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
it-people
 
PDF
The State of NoSQL
Ben Scofield
 
DOCX
How to implement joins in mongo db
Prasoon Sharma
 
PDF
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
PDF
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
PDF
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
PDF
Utopia Kindgoms scaling case: From 4 to 50K users
Jaime Buelta
 
PDF
Data normalization & memoized denormalization
Salsita Software
 
PPTX
CodeIgniter Class Reference
Jamshid Hashimi
 
PDF
Database madness with_mongoengine_and_sql_alchemy
Jaime Buelta
 
DOCX
Rental
Ahmad M
 
ODP
A Year With MongoDB: The Tips
Rizky Abdilah
 
PDF
Symfony2 from the Trenches
Jonathan Wage
 
PDF
Latinoware
kchodorow
 
PDF
Quirrel & R for Dummies
John De Goes
 
PPT
React.js 20150828
LearningTech
 
PPTX
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
PPTX
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
PDF
[2019] Spring JPA의 사실과 오해
NHN FORWARD
 
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
it-people
 
The State of NoSQL
Ben Scofield
 
How to implement joins in mongo db
Prasoon Sharma
 
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
Doctrine MongoDB Object Document Mapper
Jonathan Wage
 
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
Utopia Kindgoms scaling case: From 4 to 50K users
Jaime Buelta
 
Data normalization & memoized denormalization
Salsita Software
 
CodeIgniter Class Reference
Jamshid Hashimi
 
Database madness with_mongoengine_and_sql_alchemy
Jaime Buelta
 
Rental
Ahmad M
 
A Year With MongoDB: The Tips
Rizky Abdilah
 
Symfony2 from the Trenches
Jonathan Wage
 
Latinoware
kchodorow
 
Quirrel & R for Dummies
John De Goes
 
React.js 20150828
LearningTech
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Alex Hardman
 
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
[2019] Spring JPA의 사실과 오해
NHN FORWARD
 

Similar to Introduction To Core Data (20)

PPT
Core data orlando i os dev group
Andrew Kozlik
 
PDF
Core data WIPJam workshop @ MWC'14
Diego Freniche Brito
 
KEY
iOSDevCamp 2011 Core Data
Chris Mar
 
PDF
Core data basic Workshop slides NSSpain 2013
Diego Freniche Brito
 
PDF
Core data intermediate Workshop at NSSpain 2013
Diego Freniche Brito
 
PDF
Intro to Core Data
Make School
 
PDF
CoreData
Ali Akhtar
 
PDF
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
Denis_infinum
 
KEY
Data perisistance i_os
Michał Tuszyński
 
KEY
Data perisistence in iOS
mobiledeveloperpl
 
KEY
solving little problems
removed_e334947d661d520b05c7f698a45590c4
 
PDF
Core data in Swfit
allanh0526
 
PDF
CoreData - there is an ORM you can like!
Tomáš Jukin
 
PDF
Iphone programming: Core Data Tutorial for iOS
Kenny Nguyen
 
KEY
Core Data
Robert Brown
 
PDF
High Performance Core Data
Matthew Morey
 
PDF
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
smn-automate
 
PPT
Core Data Migration
Monica Kurup
 
PDF
Core data ios10changes
G ABHISEK
 
PDF
CoreData Best Practices (2021)
deeje cooley
 
Core data orlando i os dev group
Andrew Kozlik
 
Core data WIPJam workshop @ MWC'14
Diego Freniche Brito
 
iOSDevCamp 2011 Core Data
Chris Mar
 
Core data basic Workshop slides NSSpain 2013
Diego Freniche Brito
 
Core data intermediate Workshop at NSSpain 2013
Diego Freniche Brito
 
Intro to Core Data
Make School
 
CoreData
Ali Akhtar
 
Infinum iOS Talks S01E02 - Things every iOS developer should know about Core ...
Denis_infinum
 
Data perisistance i_os
Michał Tuszyński
 
Data perisistence in iOS
mobiledeveloperpl
 
Core data in Swfit
allanh0526
 
CoreData - there is an ORM you can like!
Tomáš Jukin
 
Iphone programming: Core Data Tutorial for iOS
Kenny Nguyen
 
Core Data
Robert Brown
 
High Performance Core Data
Matthew Morey
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
smn-automate
 
Core Data Migration
Monica Kurup
 
Core data ios10changes
G ABHISEK
 
CoreData Best Practices (2021)
deeje cooley
 
Ad

Recently uploaded (20)

PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
July Patch Tuesday
Ivanti
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Designing Production-Ready AI Agents
Kunal Rai
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
July Patch Tuesday
Ivanti
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Ad

Introduction To Core Data

  • 1. Introduction to Core Data Daniel Tull
  • 2. Sky+ Little Spender Weather Maps Fourgy
  • 5. Attributes NSNumber NSString Transformable BOOL You put in code to transform the NSDate object or value into NSData a compatible type. Transformable
  • 6. Relationships Properties that reference other objects Can be to-one or to-many (NSSet - unordered) Can (and should) have inverses, which are worked out by Core Data when you set the other property Delete rule ensures propagation
  • 7. Relationships DTAlbum Attributes DTArtist name DTGenre Attributes discCount Attributes name trackCount name Relationships Relationships Relationships albums artist artists genres composers songs songs songs
  • 8. Core Data Stack NSManagedObjectContext NSPersistentStoreCoordinator NSPersistentStore NSManagedObjectModel
  • 9. Create and Save Objects DTSong *song = [NSEntityDescription insertNewObjectForEntityForName:@“DTSong” inManagedObjectContext:managedObjectContext]; DTArtist *artist = [NSEntityDescription insertNewObjectForEntityForName:@“DTArtist” inManagedObjectContext:managedObjectContext]; artist.name = @“Moby”; song.title = @“Porcelain”; song.artist = artist; ••• NSError *error = nil; [managedObjectContext save:&error];
  • 10. Create and Save Objects NSManagedObjectContext DTArtist DTSong NSPersistentStoreCoordinator NSPersistentStore NSManagedObjectModel
  • 11. Fetching Objects All songs by “La Roux” sorted by title. Entity DTSong Predicate @“artist.name == %@”, @“La Roux” Sorting @“title”
  • 12. Fetching Objects Fetch all playlists which contain more than an hour of music. Entity DTPlaylist Predicate @“@sum.songs.duration > 3600” Sorting @“name”
  • 13. Fetching Objects NSEntityDescription *entity = [NSEntityDescription entityForName:@“DTSong” inManagedObjectContext:managedObjectContext]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@“artist.name == %@”, @“La Roux”]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@“title” ascending:YES]; NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor]; NSFetchRequest *request = [[NSFetchRequest alloc] init]; [request setEntity:entity]; [request setPredicate:predicate]; [request setSortDescriptors:sortDescriptors]; NSArray *fetchResult = [managedObjectContext executeFetchRequest:request error:&error];
  • 14. Fetching Objects NSManagedObjectContext NSFetchRequest DTArtist DTSong DTSong DTSong DTSong NSPersistentStoreCoordinator NSPersistentStore DTSong NSManagedObjectModel DTSong DTSong
  • 15. Performance: Faults Faults are placeholders for related objects, which mean you don’t use memory on unwanted objects. DTSong DTSong DTArtist DTSong DTSong DTSong
  • 16. Performance: Batching DTArtist DTArtist Batching allows you to bring only a DTArtist subset of objects DTArtist into memory. DTArtist DTArtist
  • 17. Demo
  • 19. DTGridView DTSwapView hg.danieltull.co.uk/dtkit