I am trying to understand the behavior of an NSNumber bound to an NSTextField. It seems that an NSNumber isn't always and NSNumber.

----------------------
SET UP

I have a class with an NSNumber* bound to an NSTextField via an Object Controller
        NSNumber*  <---> NSObjectController  <---> NSTextField

Accessors to the NSNumber* are created via
        @property (nonatomic, retain) NSNumber* myNum;

The object is initialized as
        myNum = [[NSNumber alloc] initWithInt: 5];

----------------------
BEHAVIOR

Then I have an action method to query some aspects of myNum. Before changing the number in the NSTextField I get the following:

        myNum is NOT a member if NSNumber
        myNum IS a kind of NSNumber
        myNum responds to intValue
        myNum responds to unsignedLongValue


After changing the value in the NSTextField to say 3, I get the following results from querying myNum:

        myNum is NOT a member if NSNumber
        myNum is NOT a kind of NSNumber
        myNum responds to intValue
        myNum does NOT responds to unsignedLongValue


----------------------
QUESTIONS:
(1) Why does [myNum isMemberOfClass:[NSNumber class]] return NO when I explicitly did an [NSNumber alloc]?

(2) [myNum isKindOfClass:[NSNumber class]] returns YES, so what type of subclasses are there to NSNumber?

(3) After changing the value in the text field, myNum is neither an NSNumber of even a kind of NSNumber. What is it?

(4) I guess the answer to 3 might explain this, but after the number is changed, why does myNum still respond to intValue but *not* unsignedLongValue?

----------------------
NOTE:
By applying an NSNumberFormatter to the NSTextField, the object always is "a kind of" NSNumber and always responds to both "intValue" and "unsignedLongValue". So I guess the lesson is: If you are going to have a GUI NSTextField represent an NSNumber, you should put an NSNumberFormatter on it.


Any insights would be appreciated,

Todd

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to