首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mac中缺少NSEntityDescription setCompoundIndexes

Mac中缺少NSEntityDescription setCompoundIndexes
EN

Stack Overflow用户
提问于 2011-12-14 13:21:33
回答 1查看 244关注 0票数 0

我错过了方法

  • compoundIndexes
  • setCompoundIndexes

在MacOSX10.7SDK中的NSEntityDescription中。但是,它可以在iOS5.0SDK中获得。

另一方面,Xcode非常了解复合索引,即使在Mac下也是如此。它创建的xcdatamodels如下所示:

代码语言:javascript
复制
<entity name="OHLCV" parentEntity="Sample" syncable="YES">
    <attribute name="close" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
    <attribute name="high" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
    <attribute name="low" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
    <attribute name="open" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
    <attribute name="volume" attributeType="Integer 64" defaultValueString="0" syncable="YES"/>
    <compoundIndexes>
        <compoundIndex>
            <index value="open"/>
            <index value="close"/>
        </compoundIndex>
    </compoundIndexes>
</entity>

难道苹果忘了在Mac中包含方法的声明吗?

这是文档:

Mac:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSEntityDescription_Class/NSEntityDescription.html (这里缺少管理复合索引的部分)

iOS:http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSEntityDescription_Class/NSEntityDescription.html

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-14 20:22:32

通过自己声明未声明的方法,我成功地调用了未声明的方法(需要声明它,以便编译器接受它):

代码语言:javascript
复制
@interface NSEntityDescription ()
- (void)setCompoundIndexes:(NSArray*)anArray;
@end

在后面的代码中,我以编程方式创建了我的NSManagedObjectModel,我可以称之为:

代码语言:javascript
复制
[entity setCompoundIndexes:
    [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"open", @"close", nil], nil]
];

我认为苹果刚刚忘记将这些方法应用到CoreData API中。这个特性肯定也可以在Mac上使用,否则Xcode就不会在xcdatamodel建模工具中提供UI。

我可以进一步确认上述语句是否有效,因为我在CoreData数据库中找到了由sqlite3创建的相应的复合索引:

代码语言:javascript
复制
CREATE INDEX ZOHLCV_ZOPEN_ZCLOSE ON ZOHLV (ZOPEN, ZCLOSE);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8505194

复制
相关文章

相似问题

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