340 likes | 815 Views
Core Data on iOS. Dhwanil Karwa. Topics. What is Core Data? Framework Overview Using Core Data Demo. 1. What is Core Data?. It is not a database. It is not an Object Relational Mapping framework.
E N D
Core Data on iOS Dhwanil Karwa
Topics • What is Core Data? • Framework Overview • Using Core Data • Demo 1
What is Core Data? • It is not a database. • It is not an Object Relational Mapping framework. • Apple explains it as “Core Data is a Schema driven object graph management and persistence Framework” • It creates a layer between database and UI. 1
What is Core Data? • Performs CRUD operations • Queries values using NSPredicate • You don’t define the identity primary keys, only give relationships.
Why learn Core Data? • Before Core Data, developers had to work with Sqlite3 to save data. • Handling CRUD operations was difficult. • User was responsible to check if saved data matched the schema. • Means you are writing your own persistence Layer • Using Core Data hides Sqlite3
Storage Options • Binary • In-memory • XML only on Mac OS X • Sqlite
Core Data M-VC Controller implements Strategy for the View View Controller Model Implements Observer Core Data
Core Data Stack • Heart of Core Data • NSManagedObjectModel • NSPersistentStoreCoordinator • NSManagedObjectContext
NSManagedObjectModel • Schema for Models • Entity, Attributes, Relationships • Fetch Requests • Validation
NSManagedObjectModel Attribute Types • Integer, Decimal, Float, Double • Boolean • Date • String • Binary Data • Transformable
NSManagedObjectModel Relationships • NSSet not NSArray • One to One • One to Many • Many to Many • Delete Rules • Nullify, Cascade, Deny
NSPersistentStoreCoordinator • Coordinates access to one or more persistent stores. • Depends on Managed Object Model • Set store options
References • Apple Developer. 2012. Core Data Programming Guide https://developer.apple.com/library/mac/documentation/cocoa/conceptual/coredata/cdProgrammingGuide.html#//apple_ref/doc/uid/TP30001200-SW1 • Burkepile Adam. 2013. http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started