NSForm validation

Andreas Mayer andreas at harmless.de
Wed Nov 13 15:49:00 PST 2002


Am Mittwoch, 13.11.02 um 23:05 Uhr schrieb James Powell:

> I am surprised, because numberWithInt returns an NSNumber * and  
> NSDecimalNumber is a subclass of NSNumber.  In C++, the compiler does 
> not downcast automatically.  It looks like the Objective C compiler 
> accommodates downcasts.

Please, try to forget C++.

numberWithInt: (the colon is part of the name) is a selector you send 
to an object. In this case you send it to the NSDecimalNumber class. 
And this class (object) will, of course, return an NSDecimalNumber.

The compiler has nothing to do with this, at all.

> It is a leap of faith to assume that the instance returned by 
> numberWithInt is actually an NSDecimalNumber instance,

It's not. It's totally obvious.
This is a convenience constructor, i.e. a replacement for [[[NSNumber 
alloc] initWithInt:] autorelease]. So [NSDecimalNumber numberWithInt:] 
is the same as [[[NSDecimalNumber alloc] initWithInt:] autorelease]. As 
you can see, this creates an NSDecimalNumber. Anything else would be 
just wrong.

> but no more than to assume that a message is defined for a class when 
> it isn't present in the header.

This is OOP. Any subclass inherits all instance variables and methods 
of its superclass(es). Nothing special about that.
Get some decent class browser like AppKiDo, that will help a lot.


bye.  Andreas.




More information about the MacOSX-dev mailing list