Ios CoreData:对子表的fetchRequest
如何将Ios CoreData:对子表的fetchRequest,ios,core-data,Ios,Core Data,如何将子类别添加到类别? 我怎样才能得到一个分类的具体子类别 我需要像这样的东西 获取Subcategorie.denumire,其中Categorie.denumire==“somename” 及 我该怎么做?如何获取子表的父表名称和表的子表名称?生成NSManagedObject实体时,目标类将有一个名为toMinorGoal的NSSet(假设toMinorGoal是无序关系)。此外,XCode将生成4个辅助方法,用于在关系中添加/删除MinorGoal对象 如果需要获取MinorGoals
子类别
添加到类别
?
我怎样才能得到一个分类的具体子类别
我需要像这样的东西
获取Subcategorie.denumire,其中Categorie.denumire==“somename”
及
我该怎么做?如何获取子表的父表名称和表的子表名称?生成NSManagedObject实体时,目标类将有一个名为toMinorGoal的NSSet(假设toMinorGoal是无序关系)。此外,XCode将生成4个辅助方法,用于在关系中添加/删除MinorGoal对象
如果需要获取MinorGoals对象,只需获取目标对象,然后访问其包含所有MinorGoals对象的toMinorGoals NSSet。或者,您可以只获取MinorGoal对象,但这些对象将返回它们中的每一个(如果您不指定需要多少)
这是XCode将为您提供的生成访问器的近似示例:
- (void)addtoMinorGoaObject:(MinorGoal *)value;
- (void)removetoMinorGoalObject:(MinorGoal *)value;
- (void)addtoMinorGoal:(NSSet *)value;
- (void)removetoMinorGoal:(NSSet *)value;
希望对您有所帮助。经过几天的不同解决方案的尝试,我终于明白了这一点,多亏了这篇关于CoreData的教程:
我获取了表分类
的所有子表子类别
,如下所示:
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Subcategorie"
inManagedObjectContext:self.managedObjectContext];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"categorii.denumire == %@",self.title];
[fetchRequest setPredicate:predicate];
[fetchRequest setEntity:entity];
NSError *error;
self.listaElementeBD = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
self.title是category
的denumire
,希望对您有所帮助
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Subcategorie"
inManagedObjectContext:self.managedObjectContext];
NSPredicate * predicate = [NSPredicate predicateWithFormat:@"categorii.denumire == %@",self.title];
[fetchRequest setPredicate:predicate];
[fetchRequest setEntity:entity];
NSError *error;
self.listaElementeBD = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];