Xcode 9构建问题与NSManagedObject的日期vs NSDate [英] Xcode 9 build issue with Date vs NSDate for NSManagedObject

查看:82
本文介绍了Xcode 9构建问题与NSManagedObject的日期vs NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Xcode 9为模拟器与设备中实体的 Date 类型属性生成不同的代码。我在 Class 下的 codegen 功能设置为 category / extension

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.

直到Xcode 8.3(最新)都可以正常工作(总是 NSDate )。以下是Xcode 9(快速键4)针对属性-

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 -

在设备上自动生成的代码:-

@NSManaged public var requiredDate: Date?

AND,

打开模拟器:-

@NSManaged public var requiredDate: NSDate?

有人遇到此问题吗?对于拥有50个以上成员的项目,直到Xcode更新对其进行修复之前,最好的解决方案是什么(我希望对此有一个苹果雷达)?

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

推荐答案

让我自己回答这个问题。这些是我的观察(到目前为止)和可能的解决方案。

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

此问题似乎是随机。突然,问题消失了, codegen 终于在模拟器和设备上的 Date 上解决了。

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:我记得我测试过它至少可以在iPhone上运行SE模拟器,iPhone 7设备

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

这篇关于Xcode 9构建问题与NSManagedObject的日期vs NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆