Core Data Part1 ios7 xcode5 storyboards

Опубликовано: 24 Март 2026
на канале: nappychef35
5,443
6

Part 1:

This tutorial will teach you to create a Core Data project using XCode 5 storyboards for ios7. It will also cover NSFetchResultsController.

This allows you to extract the data from CoreData
############# CODE SPEC ###############

Core Data is an advance topic and requires you to have a good understanding of UITableView. Much of what is required is actually boiler plate. So in reality the area to focus on is actually setting up the NSFetchResultsController, so you can utilize the boilerplate code that gives you a great deal of functionality.


-(NSFetchedResultsController *) fetchResultsController {
if (_fetchResultsController !=nil) {
return _fetchResultsController;
}

//If it doesn't exist created it

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"NewCar" inManagedObjectContext:self.managedObjectContext];

NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:@"carMake" ascending:YES];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

[fetchRequest setFetchBatchSize:15];

[fetchRequest setEntity:entity];

NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"carMake" cacheName:@"carCache"];

self.fetchResultsController = theFetchedResultsController;
_fetchResultsController.delegate = self;
return _fetchResultsController;

}