标签:des style blog color io ar for sp div
1.CoreData 编写方便, 管理方便, 出错不易寻找, 整体性强, 关联性强
2.简单介绍查询的办法
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 }
标签:des style blog color io ar for sp div
原文地址:http://www.cnblogs.com/Dylan-Alice/p/Dy_CoreData_1.html