Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducere în Core Data

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Introducere în Core Data

Scurtă prezentare a componentelor și a modului de lucru în Core Data

Avatar for bolchisbolchis

bolchisbolchis

September 21, 2013

Other Decks in Programming

Transcript

  1. #import <Foundation/Foundation.h> @class Manager, Department; @interface Employee : NSObject @property

    (nonatomic, strong) NSString *firstName; @property (nonatomic, strong) NSString *lastName; @property (nonatomic, strong) Manager *manager; @property (nonatomic, strong) Department *department; @end Un exemplu sâmbătă, 21 septembrie 13
  2. #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @class Manager, Department; @interface Employee :

    NSManagedObject @property (nonatomic, retain) NSString *firstName; @property (nonatomic, retain) NSString *lastName; @property (nonatomic, retain) Manager *manager; @property (nonatomic, retain) Department *department; @end Un exemplu sâmbătă, 21 septembrie 13
  3. Stiva Managed Object Context Managed Object Model Persistent Store Coordinator

    Persistent Object Store Store File “A collection of managed objects” “A collection of entity descriptions” “A collection of stores” “A collection of object data” sâmbătă, 21 septembrie 13
  4. •NSPersistentStoreCoordinator •NSManagedObjectModel •NSManagedObject •NSManagedObjectContext •NSFetchRequest Clase @interface Employee : NSManagedObject

    @property (nonatomic, retain) NSString *firstName; @property (nonatomic, retain) NSString *lastName; @property (nonatomic, retain) Manager *manager; @property (nonatomic, retain) Department *department; @end sâmbătă, 21 septembrie 13
  5. Un exemplu “Set buying date for 2nd monitor to be

    2015 for all employees hired in 2013” sâmbătă, 21 septembrie 13
  6. NSFetchRequest *fr = [[NSFetchRequest alloc] initWithEntityName:@"Employee"]; NSPredicate *p = [NSPredicate

    predicateWithFormat:@"hiringYear == 2013"]; [fr setPredicate:p]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@”lastName” ascending:YES]; [fr setSortDescriptors:@[sd]]; NSError *error; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; sâmbătă, 21 septembrie 13
  7. NSFetchRequest *fr = [[NSFetchRequest alloc] initWithEntityName:@"Employee"]; NSPredicate *p = [NSPredicate

    predicateWithFormat:@"hiringYear == 2013"]; [fr setPredicate:p]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@”lastName” ascending:YES]; [fr setSortDescriptors:@[sd]]; NSError *error; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; sâmbătă, 21 septembrie 13
  8. NSFetchRequest *fr = [[NSFetchRequest alloc] initWithEntityName:@"Employee"]; NSPredicate *p = [NSPredicate

    predicateWithFormat:@"hiringYear == 2013"]; [fr setPredicate:p]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@”lastName” ascending:YES]; [fr setSortDescriptors:@[sd]]; NSError *error; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; sâmbătă, 21 septembrie 13
  9. NSFetchRequest *fr = [[NSFetchRequest alloc] initWithEntityName:@"Employee"]; NSPredicate *p = [NSPredicate

    predicateWithFormat:@"hiringYear == 2013"]; [fr setPredicate:p]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@”lastName” ascending:YES]; [fr setSortDescriptors:@[sd]]; NSError *error; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; sâmbătă, 21 septembrie 13
  10. NSFetchRequest *fr = [[NSFetchRequest alloc] initWithEntityName:@"Employee"]; NSPredicate *p = [NSPredicate

    predicateWithFormat:@"hiringYear == 2013"]; [fr setPredicate:p]; NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@”lastName” ascending:YES]; [fr setSortDescriptors:@[sd]]; NSError *error; NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error]; lastName: Pop buyDate: nil lastName: Furtuna buyDate: nil sâmbătă, 21 septembrie 13
  11. for (Employee *e in fetchedObjects) { e.buyDate = 2015; }

    lastName: Pop buyDate: nil lastName: Furtuna buyDate: nil lastName: Pop buyDate: nil lastName: Furtuna buyDate: nil Context Store sâmbătă, 21 septembrie 13
  12. for (Employee *e in fetchedObjects) { e.buyDate = 2015; }

    lastName: Pop buyDate: 2015 lastName: Furtuna buyDate: 2015 lastName: Pop buyDate: nil lastName: Furtuna buyDate: nil Context Store sâmbătă, 21 septembrie 13
  13. -save: for (Employee *e in fetchedObjects) { e.buyDate = 2015;

    } NSError *error; [self.managedObjectContext save:&error]; lastName: Pop buyDate: 2015 lastName: Furtuna buyDate: 2015 lastName: Pop buyDate: 2015 lastName: Furtuna buyDate: 2015 Context Store sâmbătă, 21 septembrie 13
  14. Change tracking and undo support Relationship maintenance Faulting Automatic validation

    Schema migration NSFetchedResultsController sâmbătă, 21 septembrie 13
  15. Change tracking and undo support Relationship maintenance Faulting Automatic validation

    Schema migration NSFetchedResultsController Full KVO, KVC support sâmbătă, 21 septembrie 13
  16. Change tracking and undo support Relationship maintenance Faulting Automatic validation

    Schema migration NSFetchedResultsController Full KVO, KVC support Merge policies NSPredicate querying External data repositories iCloud integration sâmbătă, 21 septembrie 13