Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Cocoa NSPredicate包含三个实体_Cocoa_Nspredicate_Fetch - Fatal编程技术网

Cocoa NSPredicate包含三个实体

Cocoa NSPredicate包含三个实体,cocoa,nspredicate,fetch,Cocoa,Nspredicate,Fetch,我在模型图()中有3个实体: 公司>个人获取请求上的NSDictionaryResultType不允许多个关系。这就是为什么字典中没有填充inRole.name。首先,在谓词中,in指定右手参数是数组;[selectedCompany employee]是否返回数组?其次,dictionary结果类型fetches不能返回对多的关系;“inRole”是一种多对多关系吗?谢谢Patrick,我删除了request.resultType=NSDictionaryResultType;现在关系开始了。

我在模型图()中有3个实体:


公司>个人获取请求上的
NSDictionaryResultType
不允许多个关系。这就是为什么字典中没有填充
inRole.name

首先,在谓词中,in指定右手参数是数组;[selectedCompany employee]是否返回数组?其次,dictionary结果类型fetches不能返回对多的关系;“inRole”是一种多对多关系吗?谢谢Patrick,我删除了request.resultType=NSDictionaryResultType;现在关系开始了。如果你不回答这个问题作为答案,系统将永远打开它,你将无法获得学分。@bioglp我已经在下面写出了我的答案,如果它是你问题的解决方案,请选中复选标记,将其作为正确答案接受。
NSEntityDescription *entity = [NSEntityDescription entityForName:@“Person” inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];

request.predicate = [NSPredicate predicateWithFormat:@"self in %@",[selectedCompany employee]];
[request setEntity:entity];
request.resultType = NSDictionaryResultType;

NSError *error;
NSArray *fetchedObjects = [_managedObjectContext executeFetchRequest:request error:&error];

NSLog(@"%@",[fetchedObjects valueForKey:@“firstName”]); // OK
NSLog(@"%@",[fetchedObjects valueForKey:@“inRole.name”]); // NULL!!!