Problems with NSDate earlyDate in iOS 5

Prior to iOS 5, I could use the == operator to check the returned date from earlierDate :

 if ([aDate earlierDate:bDate] == aDate) [someone doSomething]; 

But now I have to do this:

 if ([[aDate earlierDate:bDate] isEqualToDate:aDate]) [someone doSomething]; 

Why is this so?

Actually, the problem is using == to compare and use isEqualToDate: and less to call earlierDate:

+4
source share
1 answer

You used pointer comparison ( == ), and now you need to use the object comparison method. This means that in earlier versions of iOS, the earlierDate: method returned the object you passed earlier. Now, it seems, a new object is created (with the same data as the earlier date), and returns this.

The isEqualToDate: method isEqualToDate: preferable because it is more suitable, and is less likely to break, as the comparison with the pointer did.

+6
source

All Articles