iOS: Can't compile CoreData model because of Fetched Indexes in Xcode 9

只愿长相守 提交于 2020-02-03 04:33:29

问题


According to the release notes, Xcode 9 adds support for fetched indexes:

"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)"

My project has Deployment Target set to iOS 9 at the moment a yet I can't compile my CoreData model, it gives me the following errors for every entity that has a compound index set:

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  

Any idea how to fix the build error?

UPDATE:

Xcode 9 correctly converts compound indexes into fetch indexes for all cases except those created from relationships, as noted in the "Known Issues" section:

The data model editor only supports creating fetch indexes from attributes and expressions in this beta, not from relationships. (32407895)

The affected fetch indexes look like this and the only attributes can be selected from the dropdown menu:

However, there's no workaround described in the document.


回答1:


I just ran into this issue in the Xcode 9 GM. What I observed was that unchecking the Ascending checkbox in the index editor caused this error to occur (it was only showing up after I made a new index). I am assuming that adjusting this index attribute is only supported in the iOS 11 fetch indexes (you'll notice any index you made prior to Xcode 9 are listed as ascending by default).

TL;DR: Make sure the Ascending checkbox is checked for all properties in the fetch index editor.




回答2:


This is fixed in Xcode 9 beta 2, according to the release notes:

The Xcode data model editor supports creating fetch indexes from attributes, expressions, and relationships. (32407895)




回答3:


I've filed a bug with Apple - as there doesn't seem to be a good fix. For now, I've changed the "Tools Version" from Automatic/Xcode 9 to Xcode 8. That fixed my problem until the bug is fixed.

Its also possible that some Models simply aren't compatible with the new indexes. In my case, it was subclassed models (i.e. from abstract classes) that had relationships to other types. For example:

PIFolder
|
|-----PIFolderProject -> index: defaultItem (task relationship)
|-----PIFolderNotebook-> index: defaultItem (note relationship)


来源:https://stackoverflow.com/questions/44386614/ios-cant-compile-coredata-model-because-of-fetched-indexes-in-xcode-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!