迅速比较NSDates

时间:2015-03-03 15:39:12

标签: ios iphone xcode swift

我有两个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 is not identical to NSComparsionResult

我不想为while语句创建另一个值,还有其他方法可以让它工作吗?

1 个答案:

答案 0 :(得分:3)

do-while statement看起来像这样:

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