core-dataxcode9-beta

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


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:

enter image description here

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


Solution

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