检查 NSDate 是否包含日期或为空
查看 NSDate 是否实际设置为日期或为空的最佳方法是什么?返回其描述或将其更改为字符串会返回“(null)”...?
谢谢。
What would be the best way to see if an NSDate is actually set to a date or is empty? Returning its description or changing it to string returns "(null)"...?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想查看 NSDate 的实例(或任何对象)是否为 nil,只需将其与 nil 进行比较即可。非空的
NSDate
对象永远不会为空;它总是包含一个日期。-init
和+date
都返回一个初始化为当前日期和时间的NSDate
对象,并且没有其他方法可以创建它的实例这堂课。If you want to see if an instance of
NSDate
(or any object) is nil, just compare it to nil. A non-nullNSDate
object will never be empty; it always contains a date. Both-init
and+date
return anNSDate
object initialized to the current date and time, and there is no other way to create an instance of this class.如果它不包含日期,那么你有一个 nil 指针,所以简单
或更明确
if it doesn't hold a date, then you have a nil pointer, so simply
or more explicitly