.
NSMutableArray *carArray;
@property (nonatomic, retain) NSMutableArray *carArray;
, . , ,
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Car" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:fetchRequest error:&error] mutableCopy];
if (mutableFetchResults == nil) {
NSLog(@"[AddCarViewController] deselect car: car not found.");
} else {
[self setCarArray:mutableFetchResults];
}
, , , , . , , . :
NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:@"selected" ascending:YES];
[carArray sortUsingDescriptors:[NSArray arrayWithObject:sorter]];
, .
, , . , MOC , nil, . , - :
if (![self.managedObjectContext save:&error]) {
NSLog(@"failed with error %@", error);
}
, . , , Car. - NSLog(@"selected car %@", carToSave);