0

Consider the following code

NSManagedObject *o = ... ;

o.myProperty = [NSDate date];

NSDate *a = o.myProperty;
NSDate *b = o.myProperty;

BOOL identical = (a==b);
BOOL equal = [a isEqual:b];

running this on my iPhone with iOS 5 sets identical = NO and equal = YES

Is this expected behavior? I would have thought that reading a property returns always the same object and doesn't create a new one everytime the getter is called.

Or is this a bug in iOS?

Tom
  • 260
  • 4
  • 13

1 Answers1

0

Well if you are comparing objects then always use equalObjects: rather than just using == comparison operator. By the way, you should use compare: method in this case to compare to dates if they are the same. In your context, you should use it like this,

[a compare:b] == NSOrderedSame // both the date are same, whatever the object br
Sandeep
  • 20,908
  • 7
  • 66
  • 106