假设我有核心数据实体a和B,其中B通过属性a指向A。
给定B的NSEntityDescription,以及A的给定属性的密钥路径(例如@"a.name"),有没有办法恢复A的NSEntityDescription?
谢谢,
时间
发布于 2012-06-13 16:39:56
我通过自己解析密钥路径成功地做到了这一点:
// Split the path to the section name up
NSArray *keyNameParts = [sectionNameKeyPath componentsSeparatedByString:@"."];
// Follow this back to the Entity description for the Section Entity
for (int idx = 0; idx < keyNameParts.count - 1; idx++) {
NSDictionary *relationships = entityDescription.relationshipsByName;
NSString *partName = [keyNameParts objectAtIndex:idx];
NSRelationshipDescription *relationshipDescription = [relationships objectForKey:partName];
if (!relationshipDescription)
{
[NSException raise:@"Relationship not found for keypath"
format:@"Entity '%@' does not point to a relationshop for '%@' in keypath '@'.", entityName, partName, sectionNameKeyPath];
}
entityDescription = relationshipDescription.entity;
} 如果有更直接的方法,我很想知道。
https://stackoverflow.com/questions/11010827
复制相似问题