SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

Сергей Матвеенко: MongoEngine: NoORM for NoSQL
Сергей Матвеенко: MongoEngine: NoORM for NoSQLСергей Матвеенко: MongoEngine: NoORM for NoSQL
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
it-people
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
Jaime Buelta
 

La actualidad más candente (20)

Сергей Матвеенко: MongoEngine: NoORM for NoSQL
Сергей Матвеенко: MongoEngine: NoORM for NoSQLСергей Матвеенко: MongoEngine: NoORM for NoSQL
Сергей Матвеенко: MongoEngine: NoORM for NoSQL
 
The State of NoSQL
The State of NoSQLThe State of NoSQL
The State of NoSQL
 
How to implement joins in mongo db
How to implement joins in mongo dbHow to implement joins in mongo db
How to implement joins in mongo db
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
Utopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersUtopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K users
 
Data normalization & memoized denormalization
Data normalization & memoized denormalizationData normalization & memoized denormalization
Data normalization & memoized denormalization
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
 
Rental
RentalRental
Rental
 
A Year With MongoDB: The Tips
A Year With MongoDB: The TipsA Year With MongoDB: The Tips
A Year With MongoDB: The Tips
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Latinoware
LatinowareLatinoware
Latinoware
 
Quirrel & R for Dummies
Quirrel & R for DummiesQuirrel & R for Dummies
Quirrel & R for Dummies
 
React.js 20150828
React.js 20150828React.js 20150828
React.js 20150828
 
Using Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data VisualisationUsing Arbor/ RGraph JS libaries for Data Visualisation
Using Arbor/ RGraph JS libaries for Data Visualisation
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
[2019] Spring JPA의 사실과 오해
[2019] Spring JPA의 사실과 오해[2019] Spring JPA의 사실과 오해
[2019] Spring JPA의 사실과 오해
 

Similar a Introduction To Core Data

20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
Kazuki Yoshida
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
hardjasonoco14599
 

Similar a Introduction To Core Data (20)

20130215 Reading data into R
20130215 Reading data into R20130215 Reading data into R
20130215 Reading data into R
 
Designing a database like an archaeologist
Designing a database like an archaeologistDesigning a database like an archaeologist
Designing a database like an archaeologist
 
Core data in Swfit
Core data in SwfitCore data in Swfit
Core data in Swfit
 
iOSDevCamp 2011 Core Data
iOSDevCamp 2011 Core DataiOSDevCamp 2011 Core Data
iOSDevCamp 2011 Core Data
 
Dex Technical Seminar (April 2011)
Dex Technical Seminar (April 2011)Dex Technical Seminar (April 2011)
Dex Technical Seminar (April 2011)
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
360|iDev
360|iDev360|iDev
360|iDev
 
RaleighFS v5
RaleighFS v5RaleighFS v5
RaleighFS v5
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Write a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdfWrite a C++ program that implements a binary search tree (BST) to man.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009Building DSLs with Xtext - Eclipse Modeling Day 2009
Building DSLs with Xtext - Eclipse Modeling Day 2009
 
Sql server lab_2
Sql server lab_2Sql server lab_2
Sql server lab_2
 
Lecture 04
Lecture 04Lecture 04
Lecture 04
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCode
 
Sequel
SequelSequel
Sequel
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj TalkSpark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
 
Authorship Attribution and Forensic Linguistics with Python/Scikit-Learn/Pand...
Authorship Attribution and Forensic Linguistics with Python/Scikit-Learn/Pand...Authorship Attribution and Forensic Linguistics with Python/Scikit-Learn/Pand...
Authorship Attribution and Forensic Linguistics with Python/Scikit-Learn/Pand...
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

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