Swift 3 - 比较Date对象 [英] Swift 3 - Comparing Date objects
问题描述
我正在将我的应用更新为Swift 3.0语法(我知道它仍然处于测试阶段,但我想在发布后立即做好准备)。
I'm updating my app to Swift 3.0 syntax (I know it's still in beta but I want to be prepared as soon as it released).
在上一个Xcode测试版(Beta 5)之前,我能够使用操作数<比较两个 Date
对象code>< ,>
和 ==
。但在最新的测试版(Beta 6)中,这已不再适用了。以下是一些截图:
Until the previous Beta of Xcode (Beta 5) I was able to compare two Date
objects using the operands <
, >
and ==
. But in the latest beta (Beta 6) this isn't working any more. Here are some screenshots:
正如您在两个屏幕截图中看到的,这些是两个 Date
对象。但是我收到以下错误:
As you can see in both screenshots, these are two Date
objects. But I get the following error:
我做错了什么?这些函数仍然在 Date
类中声明:
What am I doing wrong? The functions are still declared in the Date
class:
static func>(日期,日期)
如果左手日期时间较晚,则返回true比右手Date。
Returns true if the left hand Date is later in time than the right hand Date.
这只是一个Beta bug还是我做错了什么?
Is this just a Beta bug or am I doing something wrong?
推荐答案
我在XCode 8 beta 6中尝试过这个片段,它运行正常。
I have tried this snippet in XCode 8 beta 6, and it is working fine.
let date1 = Date()
let date2 = Date().addingTimeInterval(100)
if date1 == date2
{
}
else if date1 > date2
{
}
else if date1 < date2
{
}
这篇关于Swift 3 - 比较Date对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!