Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CoreData:对子表的fetchRequest_Ios_Core Data - Fatal编程技术网

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];