• 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
NSNumber bound to NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSNumber bound to NSTextField


  • Subject: NSNumber bound to NSTextField
  • From: Todd Heberlein <email@hidden>
  • Date: Mon, 14 Sep 2009 17:17:23 -0700

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@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>
  • Prev by Date: Filtering a table view using NSSearchField
  • Next by Date: Re: Help book content
  • Previous by thread: Re: Filtering a table view using NSSearchField
  • Next by thread: Re: NSNumber bound to NSTextField
  • Index(es):
    • Date
    • Thread