首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从密钥路径恢复NSEntityDescription

从密钥路径恢复NSEntityDescription
EN

Stack Overflow用户
提问于 2012-06-13 16:20:43
回答 1查看 94关注 0票数 1

假设我有核心数据实体a和B,其中B通过属性a指向A。

给定B的NSEntityDescription,以及A的给定属性的密钥路径(例如@"a.name"),有没有办法恢复A的NSEntityDescription?

谢谢,

时间

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-06-13 16:39:56

我通过自己解析密钥路径成功地做到了这一点:

代码语言:javascript
复制
    // 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;
    } 

如果有更直接的方法,我很想知道。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11010827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档