我错过了方法
在MacOSX10.7SDK中的NSEntityDescription中。但是,它可以在iOS5.0SDK中获得。
另一方面,Xcode非常了解复合索引,即使在Mac下也是如此。它创建的xcdatamodels如下所示:
<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
发布于 2011-12-14 20:22:32
通过自己声明未声明的方法,我成功地调用了未声明的方法(需要声明它,以便编译器接受它):
@interface NSEntityDescription ()
- (void)setCompoundIndexes:(NSArray*)anArray;
@end在后面的代码中,我以编程方式创建了我的NSManagedObjectModel,我可以称之为:
[entity setCompoundIndexes:
[NSArray arrayWithObjects:[NSArray arrayWithObjects:@"open", @"close", nil], nil]
];我认为苹果刚刚忘记将这些方法应用到CoreData API中。这个特性肯定也可以在Mac上使用,否则Xcode就不会在xcdatamodel建模工具中提供UI。
我可以进一步确认上述语句是否有效,因为我在CoreData数据库中找到了由sqlite3创建的相应的复合索引:
CREATE INDEX ZOHLCV_ZOPEN_ZCLOSE ON ZOHLV (ZOPEN, ZCLOSE);https://stackoverflow.com/questions/8505194
复制相似问题