Xcode 9 build error with Date vs NSDate for NSManagedObject

Xcode 9 generates different code for an attribute of the Date type of the object in the simulator and device. I have a codegen function in Class set to category/extension in coredata.

Prior to Xcode 8.3 (the latter), everything worked fine ( NSDate always). Below is the code automatically generated by Xcode 9 (Swift 4) code for the attribute

On the device : -

 @NSManaged public var requiredDate: Date? 

and

In the simulator : -

 @NSManaged public var requiredDate: NSDate? 

enter image description here

Has anyone encountered this issue? What is the best solution for a 50+ member project to fix this until the Xcode update fixes it (I hope there is an apple radar for this)?

+7
date xcode core-data nsmanagedobject codegen
source share
1 answer

Let me answer it myself. These are my observations (for now) and a potential solution.

This problem seems to be RANDOM . Suddenly, the problem disappeared, and codegen finally settled on Date on both simulators and the device.

However, I applied a macro-based solution (and now no longer needed) to solve it -

 // Workaround for Xcode 9 bug. The autogenerated code for 'Date' type attribute is NSDate vs Date based on device vs simualtor. // This macro condition should be removed once an Xcode update fixes this issue #if (arch(i386) || arch(x86_64)) // Simulator requiredDate <- (map["requiredDate"], NSDateTransform()) // milliseconds to NSDate #else // Device requiredDate <- (map["requiredDate"], DateTransform()) // milliseconds to Date #endif 

PS: I remember that I tested it while working at least on iPhone SE Simulator, an iPhone 7 device.

+6
source share

All Articles