如何按类名获取iOS CoreData

如何按类名获取iOS CoreData,ios,core-data,Ios,Core Data,我有一个iOS项目,我正在尝试使用CoreData 在我的模型中,我有两个类ChildA和ChildB,它们继承自ParentClass 在我的UITableViewController中,我可以轻松获得所有对象,包括: NSEntityDescription*entity=[NSEntityDescription entityForName:@“父类”在managedObjectContext:self.managedObjectContext] 我现在试图实现的是按Classname对结果进

我有一个iOS项目,我正在尝试使用CoreData

在我的模型中,我有两个类
ChildA
ChildB
,它们继承自
ParentClass

在我的
UITableViewController
中,我可以轻松获得所有对象,包括:

NSEntityDescription*entity=[NSEntityDescription entityForName:@“父类”在managedObjectContext:self.managedObjectContext]

我现在试图实现的是按
Classname
对结果进行分组。但是我不知道如何在我的
NSFetchedResultsController
中为param
sectionNameKeyPath

NSFetchedResultsController*aFetchedResultsController=[[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@“??”cacheName:@“Master”]

我想在我的
UITableView
中使用的结果应该是

ChildA
   Obj1
   Obj2
   Obj3
   ...
ChildB
   Obj4
   Obj5
   Obj6
   ...

提前感谢

我找到了一个可能的方法来实现这一点

我在我的UITableViewController中声明了两个NSFetchedResultsController

@interface MMPOITableViewController : UITableViewController <NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *childAFetchedResultsController;
@property (strong, nonatomic) NSFetchedResultsController *childBFetchedResultsController;
@end
@接口MMPOITableViewController:UITableViewController
@属性(强,非原子)NSFetchedResultsController*childAFetchedResultsController;
@属性(强,非原子)NSFetchedResultsController*childBFetchedResultsController;
@结束
第一个负责管理类
ChildA
的对象,第二个负责管理类
ChildB
的对象

然后我设法使用了
childAFetchedResultsController
childBFetchedResultsController
,具体取决于当前节

希望它能帮助其他人;)