1. coredata is easy to write, easy to manage, difficult to find errors, comprehensive, and highly correlated
2. A brief introduction to the query method
1 #pragma mark - 2 - (NSMutableArray *) findAll { 3 NSManagedObjectContext * cxt = [self managedObjectContext]; 4 5 NSEntityDescription * entityDescription = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:cxt]; 6 NSFetchRequest * request = [[NSFetchRequest alloc] init]; 7 [request setEntity:entityDescription]; 8 9 NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];10 [request setSortDescriptors:@[sortDescriptor]];11 12 NSError * error = nil;13 NSArray * listData = [cxt executeFetchRequest:request error:&error];14 NSMutableArray * resListArray = [[NSMutableArray alloc] init];15 16 for (Person * handle in listData) {17 Person * person = [[Person alloc] init];18 person.name = handle.name;19 person.age = handle.age;20 21 [resListArray addObject:person];22 }23 24 return resListArray;25 }
Coredata simple teaching (2)