Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9 build issue with Date vs NSDate for NSManagedObject

Xcode 9 generates different code for Date type attribute of the entity in simulator vs device. I have codegen feature under Class set to category/extension in coredata.

Until Xcode 8.3 (latest) it was all working fine (NSDate always). Below is the auto generated code by Xcode 9 (Swift 4) for the attribute -

On Device:-

@NSManaged public var requiredDate: Date?

AND,

On Simulator:-

@NSManaged public var requiredDate: NSDate?

enter image description here

Anyone encountered this problem? What is the best solution for a project with 50+ members to fix this until an Xcode update fix it (I hope there is an apple radar for this)?

like image 884
Ashok Avatar asked Sep 22 '17 17:09

Ashok


1 Answers

Let me answer this myself. These are my observations (so far) and potential solution.

This issue seems RANDOM. Suddenly, the issue has disappeared and codegen has finally settled on Date on both simulator and device.

However, I applied 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 I tested it working at least on iPhone SE Simulator, iPhone 7 device

like image 84
Ashok Avatar answered Sep 30 '22 17:09

Ashok