正如在 WWDC 上提到的,iOS 11 应该支持索引核心数据,以便可以通过 Spotlight 进行搜索。这是 WWDC 演示文稿:
但是,在观看了视频和文档之后,我仍然不知道如何设置我的核心数据对象,以便可以从手机聚光灯搜索中搜索到它们。
我想主要的问题是:
1.) 您实际上如何设置特定对象类型的哪些属性是可搜索的。
2.) 如何设置 NSCoreDataCoreSpotlightDelegate 并让它处理数据?看起来 NSPersistentStore 有一个属性
var coreSpotlightExporter: NSCoreDataCoreSpotlightDelegate
但它是只准备好的:(
我找不到任何可以清楚地解释这些内容的内容。谢谢!
最佳答案
您不直接设置 coreSpotlightExporter
。相反,使用导出委托(delegate)设置 NSCoreDataCoreSpotlightExporter
选项:
container.persistentStoreDescriptions.forEach {
$0.setOption(MyCoreDataCoreSpotlightDelegate(forStoreWith:$0, model: container.managedObjectModel), forKey:NSCoreDataCoreSpotlightExporter)
}
我在调用 loadPersistentStores(completionHandler:)
之前添加了这段代码。
要设置属性和实体,您需要为 NSAttributeDescription
和 NSEntityDescription
或 UI 中的 .xcdatamodeld
更新相应的属性。
关于ios - 在iOS 11中,如何使核心数据在核心聚光灯下可搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45623020/