On Sep 14, 2009, at 17:17, Todd Heberlein wrote:

(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?

1. Because NSNumber is a class cluster with no concrete instances. [NSNumber alloc] always returns a subclass.

2. It's an implementation detail we don't care about. If you look at a NSNumber in the debugger, it should show you the actual class, if you must know.

3. It's a NSString.

4. The answer to 3 does explain this. :) Strings do respond to intValue etc, but not to unsignedXxxValue methods.

I am trying to understand the behavior of an NSNumber bound to an NSTextField.

The underlying problem is that you can't get this understanding, because a user interface item isn't bound to an *object* but to a *property* of an object. In this case, your NSNumber object is actually "neither of the above" -- it's the *value* of the property of an object.

When you edit a text field, the property value is replaced by the text field value -- which happens to be a string. (And yes, that's going to mess things up with your NSNumber* @property definition.)

The simple solution is to add a number formatter to your text field. Then, changing the text field causes it to update the binding with a NSNumber value instead of a NSString value.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to