Re: Wisdom of overriding isEqual:
Re: Wisdom of overriding isEqual:
- Subject: Re: Wisdom of overriding isEqual:
- From: Glen Low <email@hidden>
- Date: Fri, 12 Mar 2004 13:58:05 +0800
On 12/03/2004, at 1:29 AM, email@hidden wrote:
Are there any Foundation data classes that don't explain what their
-isEqualTo...: method does?
NSNumber/NSValue. For some strange reason, NSNumber (a subclass of
NSValue) isEqualToValue: doesn't work the same as isEqual: either, so
the latter can't just be calling the former:
Try:
NSNumber* falsie = [[NSNumber alloc] initWithBool: YES];
NSNumber* falsetto = [[NSNumber alloc] initWithInt: 1];
NSLog (@"falsie is falsetto = %d", [falsie isEqual: falsetto]);
NSLog (@"falsie is falsetto = %d", [falsie isEqualToValue: falsetto]);
NSLog (@"falsie is falsetto = %d", [falsie isEqualToNumber: falsetto]);
NSLog (@"%@", [falsie className]);
NSLog (@"%@", [falsetto className]);
All calls should be valid since NSNumber is a subclass of NSValue,
which is a subclass of NSObject.
Somewhat non-intuitively, this returns:
2004-03-12 13:53:01.387 CocoaTry[548] falsie is falsetto = 1
2004-03-12 13:53:01.387 CocoaTry[548] falsie is falsetto = 0
2004-03-12 13:53:01.388 CocoaTry[548] falsie is falsetto = 1
2004-03-12 13:53:01.388 CocoaTry[548] NSCFBoolean
2004-03-12 13:53:01.388 CocoaTry[548] NSCFNumber
In Apple's defense it does say isEqualToValue: compares the type, but
then this is definitely a case where isEqualToXXX: is not the same as
isEqual:
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.