gpt4 book ai didi

swift - 使用 Swift 比较 NSDate

转载 作者:IT王子 更新时间:2023-10-29 04:55:25 26 4
gpt4 key购买 nike

我正在开发一个需要检查家庭作业截止日期的应用程序。我想知道截止日期是否在下周内,如果是则执行操作。
我能找到的大部分文档都在 Objective-C 中,我无法弄清楚如何在 Swift 中做到这一点。感谢您的帮助!!

最佳答案

如果要支持== , < , > , <= , 或 >=对于 NSDate s,你只需要在某处声明:

public func ==(lhs: NSDate, rhs: NSDate) -> Bool {
return lhs === rhs || lhs.compare(rhs) == .OrderedSame
}

public func <(lhs: NSDate, rhs: NSDate) -> Bool {
return lhs.compare(rhs) == .OrderedAscending
}

extension NSDate: Comparable { }

关于swift - 使用 Swift 比较 NSDate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26198526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com