我有一个沙盒、仅限 Mavericks、核心数据、非文档、Mac 应用程序。
对于一个实体的一个属性,我选择了“Index in Spotlight”,
在第二次尝试中,我选择了“Index in Spotlight”和“Store in External Record File”。
按照 Apples Core Data Spotlight 集成编程指南,我在第一点,你的程序:
There are three processes involved in creating and maintaining the Spotlight index:
Your program. Within your program, the Core Data framework maintains the persistent store and creates the external record files to trigger the spotlight indexing
The Spotlight importer. [...]
Core Data External Record daemon. [...]
我假设,现在,如果我运行应用程序并向其中添加数据,则必须在某个地方生成元数据(Spotlight Importer 可以索引)或外部记录文件。
我找不到这样的元数据或外部记录文件。我在我的应用程序的沙箱容器内外到处搜索。 (请注意,我还没有尝试构建 Spotlight Importer——我只是在寻找可索引的元数据。)
通常在哪里可以找到这个 Spotlight 可索引元数据?
没有生成 Spotlight 可索引元数据的原因可能是什么?
最佳答案
外部记录的目录必须位于 ~/Library/CoreData(或沙盒应用程序中的等效目录)。您必须创建它。
另外不要忘记在 Application Delegate 中为您的 PersistentStoreCoordinator 设置存储选项,就像在 - (NSPersistentStoreCoordinator *) persistentStoreCoordinator 中这样:
//creating the External Records Directory
error = nil;
NSString *externalRecordsSupportFolder = [@"~/Library/CoreData/YOUR_EXTERNAL_RECORD_DIRECTORY" stringByExpandingTildeInPath];
[fileManager createDirectoryAtPath:externalRecordsSupportFolder
withIntermediateDirectories:YES
attributes:nil
error:&error];
if(error){
[NSApp presentError:error];
}
//options for your main Persistent Store Coordinator
NSDictionary *storeOptions = @{
NSExternalRecordExtensionOption:@"YOUR_EXTERNAL_RECORD_EXTENSION",
NSExternalRecordsDirectoryOption:externalRecordsSupportFolder,
NSExternalRecordsFileFormatOption:NSXMLExternalRecordType
};
然后你传递storeOptions
NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:storeOptions error:&error]) {
[[NSApplication sharedApplication] presentError:error];
return nil;
}
关于objective-c - Core Data 应用程序不生成 Spotlight 可索引元数据(或者我找不到它),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24206439/