Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 835
Tom Kraina Avatar asked Jun 06 '17 09:06

Tom Kraina


1 Answers

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.

like image 106
Charles A. Avatar answered Nov 15 '22 01:11

Charles A.