- (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel_ != nil) { return managedObjectModel_; } NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"CoreData" ofType:@"momd"]; NSURL *modelURL = [NSURL fileURLWithPath:modelPath]; managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; return managedObjectModel_; }
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator_ != nil) { return persistentStoreCoordinator_; } NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"CoreData.sqlite"]]; NSError *error = nil; persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator_; }
NSDate* t = [managedObject valueForKey:@"updateDate"]
.xcdatamodelをクリックすると起動する。
let fetchRequest = NSFetchRequest() let entity = NSEntityDescription.entityForName("Book", inManagedObjectContext: managedObjectContext) fetchRequest.entity = entity let pred = NSPredicate(format: "shelf=%@", argumentArray: [shelf]) fetchRequest.predicate = pred
NSManagedObjectContext *addingContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [addingContext setParentContext:[self.fetchedResultsController managedObjectContext]];