Core DataBy Robert Brown@robby_brown
Basic Core Data
What is Core Data?IntimidatingAn amazing data persistence frameworkNot a database
Model View Controller Interface             View             Controller   Xcode  Builder                      Model       ...
Core Data Layers                           Application                        NSManagedObject                   NSManagedO...
Persistent Store NSPersistentStore Four storage types: XML (Mac only), SQLite, binary, and in memory Developers can add th...
Persistent Store Coordinator NSPersistentStoreCoordinator Façade between persistent store(s) and managed object context(s)...
Persistent Store CoordinatorManaged  ObjectContexts Persistent   StoreCoordinatorPersistent Stores
Managed ObjectModelNSManagedObjectModelA representation of the app’s data modelVisually built in Xcode (usually)Commonly c...
Managed ObjectModel
Entities NSEntityDescription Entities represent objects Entities can have attributes such as numbers and strings Entities ...
Managed Object ContextNSManagedObjectContextThe “scratch pad” of you applicationChanges aren’t saved until calling save:Al...
Managed ObjectNSManagedObjectSuperclass of all managed objectsProperties can be accessed via KVC/KVODon’t pass managed obj...
Fetch RequestsNSFetchRequestUsed to retrieve objects from the storeUses an NSPredicate for the query
Advanced Core Data
Fetch Request Efficiency                        Jedi                                               LevelSmaller batches may...
Fetch Request Templates                       Jedi                                              LevelCommon fetch requests...
Transient Attributes                                   Jedi                                                       Level At...
Delete Rules                                Jedi                                            LevelDeny: Don’t allow if some...
Versioning and Migration                           Jedi                                                   Level MOM is you...
Configurations                                             Jedi                                                          Le...
Demo
ResourcesApple DocumentationCore Data: Apple’s API for Persisting Data on Mac OSX by Marcus S. Zarrahttps://developer.appl...
Questions?
Upcoming SlideShare
Loading in...5
×

Core Data

2,132

Published on

Core Data can be intimidating at first. With a proper introduction, the transition into using Core Data can be much smoother. This presentation gives an overview of the core and advanced parts of Core Data.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,132
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
108
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Core Data

    1. 1. Core DataBy Robert Brown@robby_brown
    2. 2. Basic Core Data
    3. 3. What is Core Data?IntimidatingAn amazing data persistence frameworkNot a database
    4. 4. Model View Controller Interface View Controller Xcode Builder Model Core Data
    5. 5. Core Data Layers Application NSManagedObject NSManagedObjectContext NSPersistentStoreCoordinator NSManagedObjectModel NSPersistentStore XML SQLite Binary In Memory Custom
    6. 6. Persistent Store NSPersistentStore Four storage types: XML (Mac only), SQLite, binary, and in memory Developers can add their own custom formats
    7. 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. 8. Persistent Store CoordinatorManaged ObjectContexts Persistent StoreCoordinatorPersistent Stores
    9. 9. Managed ObjectModelNSManagedObjectModelA representation of the app’s data modelVisually built in Xcode (usually)Commonly called a “MOM”
    10. 10. Managed ObjectModel
    11. 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. 12. Managed Object ContextNSManagedObjectContextThe “scratch pad” of you applicationChanges aren’t saved until calling save:Always check for errorsCreate a new context for each threadCommonly called a “MOC”
    13. 13. Managed ObjectNSManagedObjectSuperclass of all managed objectsProperties can be accessed via KVC/KVODon’t pass managed objects between threads, passtheir objectID instead
    14. 14. Fetch RequestsNSFetchRequestUsed to retrieve objects from the storeUses an NSPredicate for the query
    15. 15. Advanced Core Data
    16. 16. Fetch Request Efficiency Jedi LevelSmaller batches may be requested for greaterefficiency (SQLite only)Objects may be returned as faultsSUBQUERY can be used to have the database do thework instead of Core Data
    17. 17. Fetch Request Templates Jedi LevelCommon fetch requests can be stored as a templateFor example, all persons with a given nameUse fetchRequestFromTemplateWithName:substitutionVariables:
    18. 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. 19. Delete Rules Jedi LevelDeny: Don’t allow if some relation existsNullify: Set relationship to nilCascade: Delete related objectsNo Action: Do nothing, I want to cleanup
    20. 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. 21. Configurations Jedi LevelA persistent store coordinator may only have one MOMOne MOM may have many configurationsA configuration is a subset of entitiesTypically used to store different entities in differentstores using one store coordinator
    22. 22. Demo
    23. 23. ResourcesApple DocumentationCore Data: Apple’s API for Persisting Data on Mac OSX by Marcus S. Zarrahttps://developer.apple.com/videos/wwdc/2010/
    24. 24. Questions?
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×