开发者

Check to see if NSDate holds a date or is empty

开发者 https://www.devze.com 2022-12-22 02:19 出处:网络
What w开发者_如何学Goould 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)\"...?

What w开发者_如何学Goould 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.


If you want to see if an instance of NSDate (or any object) is nil, just compare it to nil. A non-null NSDate object will never be empty; it always contains a date. Both -init and +date return an NSDate object initialized to the current date and time, and there is no other way to create an instance of this class.

   if(someData == nil) {
      // do stuff
   }


if it doesn't hold a date, then you have a nil pointer, so simply

if (!date) {
    ...
}

or more explicitly

if (date == nil) {
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消