从CoreData简单检索值返回null实体(Simple retrieving values fr

2019-09-29 11:34发布

我有两个实体。 它们被命名为SP和代码。 我分别具有在每个10点5的属性。 我有两个实体反向关系。 我输入数据到使用Firefox插件sqlite的经理模式。 所以, 我没有写这样sp.coderelationship = codeObj一条线; 或code.sprelationship = spObj; 在代码的任何地方。 现在,在一个视图控制器我正在检索数据。 self.spArray = [self.managedObjectContext executeFetchRequest:FR误差:&错误];

for(SP *spObj in self.spArray)
{
    NSLog(@"description is %@",spObj.sPDescription);
    Code *codObj = spObj.coderelationship;
    NSLog(@"it has value %@",codObj);
    NSLog(@" unique name is %@",codObj.uniqueCodeName);
}

输出是用于描述正确的。 它打印出的值“XYZ”。 但是,在过去的2记录其空。 我的实体设计

SP

-sPDescription -sPName -sPID 关系 -coderelationship


代码-codeName -codeID -codeDate 关系 -sprelationship

如果需要更多的信息,让我知道。 谢谢..

Answer 1:

执行读取请求添加以下代码之前:

NSString *relationshipKeyPath = @"coderelationship"; // Set this to the name of the relationship on "SP" that points to the "Code" objects;
NSArray *keyPaths = [NSArray arrayWithObject:relationshipKeyPath];
[fR setRelationshipKeyPathsForPrefetching:keyPaths];

此外,有你验证了关系正确插入到数据库?



文章来源: Simple retrieving values from CoreData returns null for entities