为什么 Xcode 不显示 CoreData 实体和属性的索引选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45922314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:12:08  来源:igfitidea点击:

Why Xcode does not show index options for CoreData entities and attributes?

iosxcodecore-dataindexingdeprecated

提问by Trzy Gracje

In Xcode 9 (beta 6) indexing options are missing in Data Model Inspector (.xcdatamodeldfile):

在 Xcode 9 (beta 6) 中,Data Model Inspector ( .xcdatamodeldfile)中缺少索引选项:

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

They are visible in Xcode 8:

它们在 Xcode 8 中可见:

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

Do you know what reasons are behind this decision?

你知道这个决定背后的原因是什么吗?

回答by Martin

As @tomharrington said, the solution is in the WWDC 2017 video: Indexing stuff begins at 10:32 and the demo at 16:40.

正如@tomharrington 所说,解决方案在 WWDC 2017 视频中:索引内容从 10:32 开始,演示在 16:40 开始。

It's still possible to create and index via Xcode9:

仍然可以通过 Xcode9 创建和索引:

  • First, select your entity, long-click on the + (Add Entity), and select Add Fetch Index.
  • 首先,选择您的实体,长按 +(添加实体),然后选择添加提取索引。

first step

第一步

  • Then, name your index appropriately, the select the property you want to index on (and choose ascending or descending, depending on how is organized your data) second step

  • Finally, as explained on the video, this will not trigger a migration and user that update your app will not get your index. If you want to force a model migration, add an Hash Modifier by selecting the entity, and setting Right Panel > 3rd tab > Versioning > Hash Modifier. optionally, third step

  • 然后,适当地命名您的索引,选择要索引的属性(并选择升序或降序,具体取决于数据的组织方式) 第二步

  • 最后,如视频中所述,这不会触发迁移,更新您的应用程序的用户将不会获得您的索引。如果要强制进行模型迁移,请通过选择实体并设置 Right Panel > 3rd tab > Versioning > Hash Modifier 来添加哈希修改器。 可选,第三步

回答by Tom Harrington

Simple indexing is deprecated in iOS 11, and the Xcode 9 UI reflects that. This is from the docs for NSPropertyDesciption:

iOS 11 中不推荐使用简单索引,而 Xcode 9 UI 反映了这一点。这是来自以下文档的NSPropertyDesciption

isIndexed deprecated

isIndexed 已弃用

At WWDC 2017 the What's New in Core Datasession described a new indexing API. Give that session a look.

在 WWDC 2017 上,Core Data 的新特性会议描述了一个新的索引 API。看看那个会议。