Ios 快速比较日期

Ios 快速比较日期,ios,iphone,xcode,swift,Ios,Iphone,Xcode,Swift,我有两个NSDate对象要与以下代码进行比较: var endDate = self.object.endDate var thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents) let test = thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending do { t

我有两个
NSDate
对象要与以下代码进行比较:

    var endDate = self.object.endDate
    var thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)

    let test = thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending

    do {
        timeRangeArray.addObject(thisDate!)
        currentComponents.minute += 15
        thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)
    } while thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending  {
        return timeRangeArray
    }
并且总是得到-
(()->()->$T8)->$T9与NSComparsionResult不相同

我不想为while语句创建另一个值,有没有其他方法可以实现这一点?

A看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
你的看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
我想你的意思是:

do {
    timeRangeArray.addObject(thisDate!)
    currentComponents.minute += 15
    thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)
} while thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending  

return timeRangeArray
A看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
你的看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
我想你的意思是:

do {
    timeRangeArray.addObject(thisDate!)
    currentComponents.minute += 15
    thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)
} while thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending  

return timeRangeArray
A看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
你的看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
我想你的意思是:

do {
    timeRangeArray.addObject(thisDate!)
    currentComponents.minute += 15
    thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)
} while thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending  

return timeRangeArray
A看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
你的看起来像这样:

do {
    statements
} while condition
do {
    statements
} while condition {
    // what is this???
}
我想你的意思是:

do {
    timeRangeArray.addObject(thisDate!)
    currentComponents.minute += 15
    thisDate = NSCalendar.currentCalendar().dateFromComponents(currentComponents)
} while thisDate?.compare(endDate) == NSComparisonResult.OrderedDescending  

return timeRangeArray

为什么在
return
语句周围有大括号(
{
}
)?这将它转换为一个块作为表达式的一部分。谢谢,我错过了。为什么在
return
语句周围有大括号(
{
})?这将它转换为一个块作为表达式的一部分。谢谢,我错过了。为什么在
return
语句周围有大括号(
{
})?这将它转换为一个块作为表达式的一部分。谢谢,我错过了。为什么在
return
语句周围有大括号(
{
})?这会把它转换成一个块,作为你表达的一部分。谢谢,我错过了