在iOS 11中,如何使核心数据在核心聚光灯下可搜索 [英] In iOS 11, how to make core data searchable in core spotlight

查看:64
本文介绍了在iOS 11中,如何使核心数据在核心聚光灯下可搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如WWDC所提到的,iOS 11应该支持对Core Data进行索引,以便可以通过Spotlight对其进行搜索。这是WWDC演示文稿:

As mentioned at WWDC, iOS 11 should have support to index Core Data so that it is searchable via Spotlight. This is the WWDC presentation:


https://developer.apple.com/videos/play/wwdc2017/210/

但是,在观看视频并查看文档之后,我仍然不知道如何设置我的核心数据对象,以便可以从手机的聚光灯搜索中搜索它们。

However, after watching the video and looking at docs, I still have no idea how to setup my core data objects so they are searchable from the phones spotlight search.

我猜主要问题是:

1。)您实际上是如何设置某项属性的对象类型是可搜索的。

1.) How do you actually set which attributes of a certain object type are searchable.

2。)如何设置NSCoreDataCoreSpotlightDelegate并获取它来处理数据?看来NSPersistentStore具有属性

2.) How do you setup a NSCoreDataCoreSpotlightDelegate and get it to process the data? It looks like NSPersistentStore has a property


var coreSpotlightExporter:NSCoreDataCoreSpotlightDelegate

var coreSpotlightExporter: NSCoreDataCoreSpotlightDelegate

但是它只是准备就绪的:(

but it's readyonly :(

我找不到任何可以清楚地解释这些内容的东西。谢谢!

I couldn't find anything that explained this stuff clearly. Thanks!

推荐答案

您不直接设置 coreSpotlightExporter ,而是设置 NSCoreDataCoreSpotlightExporter 选项与您的出口代表:

You do not set coreSpotlightExporter directly. Instead, set the NSCoreDataCoreSpotlightExporter option with your export delegate:

container.persistentStoreDescriptions.forEach {
    $0.setOption(MyCoreDataCoreSpotlightDelegate(forStoreWith:$0, model: container.managedObjectModel), forKey:NSCoreDataCoreSpotlightExporter)
}

我添加了此代码,然后调用 loadPersistentStores(completionHandler:)

I added this code before calling loadPersistentStores(completionHandler:).

要设置属性和实体,请为 NSAttributeDescription NSEntityDescriptio n 或在UI中的 .xcdatamodeld 中。

To set attributes and entities, you update the appropriate properties for NSAttributeDescription and NSEntityDescription or in your .xcdatamodeld in the UI.

这篇关于在iOS 11中,如何使核心数据在核心聚光灯下可搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆