如何按类名获取iOS CoreData
我有一个iOS项目,我正在尝试使用CoreData 在我的模型中,我有两个类如何按类名获取iOS CoreData,ios,core-data,Ios,Core Data,我有一个iOS项目,我正在尝试使用CoreData 在我的模型中,我有两个类ChildA和ChildB,它们继承自ParentClass 在我的UITableViewController中,我可以轻松获得所有对象,包括: NSEntityDescription*entity=[NSEntityDescription entityForName:@“父类”在managedObjectContext:self.managedObjectContext] 我现在试图实现的是按Classname对结果进
ChildA
和ChildB
,它们继承自ParentClass
在我的UITableViewController
中,我可以轻松获得所有对象,包括:
NSEntityDescription*entity=[NSEntityDescription entityForName:@“父类”在managedObjectContext:self.managedObjectContext]代码>
我现在试图实现的是按Classname
对结果进行分组。但是我不知道如何在我的NSFetchedResultsController
中为paramsectionNameKeyPath
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
,具体取决于当前节
希望它能帮助其他人;)