Core Data II: Abfragen, Toolbox

Core Data-Abfragen

Core Data: NSFetchedResultsController

Core Data Toolbox: DataQuery

Anwendungsbeispiel: DataQuery

DataQuery* query = [carRepository cars];
[query addPredicate:[carRepository predicateCarWithName:@"Skoda"]];
[query addSortBy:@"year" asc:YES];
NSArray* results = [query allResults];
Car* oldestCar = (Car*) [query firstResult];

Core Data Toolbox: CoreDataManager

Core Data Toolbox: ManagedTableViewController

Anwendungsbeispiel ManagedTableViewController

@interface CarListController : ManagedTableViewController
// ...
@end

@implementation CarListController

- (id) initWithCarRepository: (CarRepository*) aCarRepository {
    if (self = [super initWithStyle:UITableViewStylePlain
                  dataQuery: [aCarRepository cars]
         sectionNameKeyPath: @"car.maker"
            cellTextKeyPath: @"name"]) {
        // ...
    }
    return self;
}

Empfehlung: Projektstruktur

Ordnerstruktur

Weitere Informationen

Ralf Ebert

Ralf Ebert is an independent software developer, technical writer and trainer. He makes apps for Mac OS X and iOS and builds software solutions for companies using Eclipse RCP and Ruby on Rails. He offers training courses for software developers and writes books and articles about software development.