core data ios

                                        





                                                                           Umakanta Sahoo

                                                                          iOS Team @THBS


What is core data ?

  • part of the Cocoa API

 

  • introduced in the iPhone SDK 3.0

 

  • object-relational framework

 

  • Provides automatic data persistence

 

  • Efficient access

 


Why use Cora Data ?

Efficiency

 


Core Data Architecture 

  • Managed Object 

  •  Managed Object Context


  • Data storage


  • Modeling  Data 

Managed Object 

  • NSManagedObject

The individual data obj in your class represented by a class NSManagedObject

Managed Object Context

  • NSManagedObjectContext

 - Core Data's scratch pad of your projects

 - tracks changes to modal properties

 - handles actions on your data 

- central point  we work with, when we will do all things

Data storage

  • NSPersistentStore
 - Data stored in a Sqlite Database.
 - Core data sits on the top of this layer
 -  Schema and data store in a file 
        in a special format

Persistent Store Coordinator:  database connection.

 - Here’s where you set up the actual names and locations of what databases will be used to store the objects, and any time a managed object context needs to save something it goes through this single coordinator.

Modeling our Data

  • NSManagedObjectModel
  • Graphically designed in xcode and you can see how they are connected to each other.
    • ManagedObjectModel describes 

      all these obj

        Entity

        relationship

    • We can define behavior with this object.

    • It use all these information in a managedObjectModel to create a store file.

  






Fetching Data

  • NSFetchRequest
    • how you access and save data

    • Flexible and powerful

    • very simple to use. All you have to decide what to fetch, where to fetch from and how you want to brought back to code



  

Easy as 1,2,3.

 

Types

 There are bunch of ways how you can fetch


    • Faulting
    • prefetching
    • batching
    • partial faulting
    • Aggregates
   

  Faulting : 


  partial Faulting : 

  Pre Fetching : 

  Batching : 

  Aggregates : 

  • Basically data summaries.
  • In-database aggregates :  
    • sum  
    • count
    • min
    • max
    • average

Working with UI Kit


Threading

practicing safe object ownership

Core data uses a policy of isolation

    - one managedObject per thread

    - never pass managedObject between threads

    - be careful passing data between thread

    - Prefer object-id if you pass anything




core data ios

By Torry Harris Business Solutions