• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSNumber bound to NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber bound to NSTextField


  • Subject: Re: NSNumber bound to NSTextField
  • From: Quincey Morris <email@hidden>
  • Date: Mon, 14 Sep 2009 17:59:31 -0700

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 (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSNumber bound to NSTextField
      • From: Quincey Morris <email@hidden>
References: 
 >NSNumber bound to NSTextField (From: Todd Heberlein <email@hidden>)

  • Prev by Date: Re: Help book content
  • Next by Date: Shutdown/Restart computer
  • Previous by thread: NSNumber bound to NSTextField
  • Next by thread: Re: NSNumber bound to NSTextField
  • Index(es):
    • Date
    • Thread