iOS:由于 Xcode9 中的提取索引,无法编译 CoreData 模型
iOS: Can't compile CoreData model because of Fetched Indexes in Xcode 9
根据发行说明,Xcode9 添加了对获取索引的支持:
"The data model editor presents a unified interface for Core Data’s
new fetch indexes feature as well as its existing property index and
entity compound index features. Older data models are translated into
fetch index form for editing, and saved to the old file format when
necessary. Compiling a data model with a Deployment Target lower than
iOS 11, watchOS 4, macOS 10.13, or tvOS 11 continues to generate a
compatible compiled form. (30843153)"
我的项目目前将 Deployment Target 设置为 iOS 9,但我无法编译我的 CoreData 模型,对于每个具有复合索引集的实体,它都会给我以下错误:
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[0]: error: Expression requires a concrete result type.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[0]: error: Expression attributes are not compatible with the current deployment target.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[1]: error: Expression requires a concrete result type.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[1]: error: Expression attributes are not compatible with the current deployment target.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity: error: Fetch Indexes feature requires iOS deployment target 11.0 or later
Model.xcdatamodeld/Model.xcdatamodel:MyEntity: error: Fetch Indexes feature requires Xcode 9.0 tools or later
知道如何修复构建错误吗?
更新:
Xcode 9 正确地将复合索引转换为所有情况下的提取索引,但根据关系创建的除外,如 "Known Issues" 部分所述:
The data model editor only supports creating fetch indexes from attributes and expressions in this beta, not from relationships. (32407895)
受影响的提取索引如下所示,可以从下拉菜单中选择唯一的属性:
但是,文档中没有描述解决方法。
这在 Xcode 9 beta 2 中已修复,根据 release notes:
The Xcode data model editor supports creating fetch indexes from
attributes, expressions, and relationships. (32407895)
我已经向 Apple 提交了一个错误 - 因为似乎没有很好的修复方法。现在,我已经将 "Tools Version" 从 Automatic/Xcode 9 更改为 Xcode 8。这解决了我的问题,直到错误被修复。
也有可能某些模型与新索引不兼容。在我的例子中,它是与其他类型有关系的子类模型(即来自抽象 类)。例如:
PIFolder
|
|-----PIFolderProject -> index: defaultItem (task relationship)
|-----PIFolderNotebook-> index: defaultItem (note relationship)
我刚刚运行在Xcode 9 GM 中进入这个问题。我观察到的是取消选中索引编辑器中的 Ascending
复选框导致发生此错误(它仅在我创建新索引后出现)。我假设仅在 iOS 11 提取索引中支持调整此索引属性(您会注意到在 Xcode 9 之前创建的任何索引默认情况下都列为升序)。
TL;DR:确保在抓取索引编辑器中为所有属性选中 Ascending
复选框。
得到后就来了
cdtool[0] Entity already has an index with name
正在尝试将基本目标升级到 iOS11。
经过几天的反复试验,解决方法是使用唯一名称重命名索引
在 iOS 之前,11 个索引名称不是唯一的,所以我有 2 个 byRankIndex。
将它们更改为唯一的名称修复了它。
根据发行说明,Xcode9 添加了对获取索引的支持:
"The data model editor presents a unified interface for Core Data’s new fetch indexes feature as well as its existing property index and entity compound index features. Older data models are translated into fetch index form for editing, and saved to the old file format when necessary. Compiling a data model with a Deployment Target lower than iOS 11, watchOS 4, macOS 10.13, or tvOS 11 continues to generate a compatible compiled form. (30843153)"
我的项目目前将 Deployment Target 设置为 iOS 9,但我无法编译我的 CoreData 模型,对于每个具有复合索引集的实体,它都会给我以下错误:
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[0]: error: Expression requires a concrete result type.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[0]: error: Expression attributes are not compatible with the current deployment target.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[1]: error: Expression requires a concrete result type.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity|compoundIndex[1]: error: Expression attributes are not compatible with the current deployment target.
Model.xcdatamodeld/Model.xcdatamodel:MyEntity: error: Fetch Indexes feature requires iOS deployment target 11.0 or later
Model.xcdatamodeld/Model.xcdatamodel:MyEntity: error: Fetch Indexes feature requires Xcode 9.0 tools or later
知道如何修复构建错误吗?
更新:
Xcode 9 正确地将复合索引转换为所有情况下的提取索引,但根据关系创建的除外,如 "Known Issues" 部分所述:
The data model editor only supports creating fetch indexes from attributes and expressions in this beta, not from relationships. (32407895)
受影响的提取索引如下所示,可以从下拉菜单中选择唯一的属性:
但是,文档中没有描述解决方法。
这在 Xcode 9 beta 2 中已修复,根据 release notes:
The Xcode data model editor supports creating fetch indexes from attributes, expressions, and relationships. (32407895)
我已经向 Apple 提交了一个错误 - 因为似乎没有很好的修复方法。现在,我已经将 "Tools Version" 从 Automatic/Xcode 9 更改为 Xcode 8。这解决了我的问题,直到错误被修复。
也有可能某些模型与新索引不兼容。在我的例子中,它是与其他类型有关系的子类模型(即来自抽象 类)。例如:
PIFolder
|
|-----PIFolderProject -> index: defaultItem (task relationship)
|-----PIFolderNotebook-> index: defaultItem (note relationship)
我刚刚运行在Xcode 9 GM 中进入这个问题。我观察到的是取消选中索引编辑器中的 Ascending
复选框导致发生此错误(它仅在我创建新索引后出现)。我假设仅在 iOS 11 提取索引中支持调整此索引属性(您会注意到在 Xcode 9 之前创建的任何索引默认情况下都列为升序)。
TL;DR:确保在抓取索引编辑器中为所有属性选中 Ascending
复选框。
得到后就来了
cdtool[0] Entity already has an index with name
正在尝试将基本目标升级到 iOS11。
经过几天的反复试验,解决方法是使用唯一名称重命名索引
在 iOS 之前,11 个索引名称不是唯一的,所以我有 2 个 byRankIndex。 将它们更改为唯一的名称修复了它。