• 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: unrecognized selector error when calling -stringValue on NSNumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unrecognized selector error when calling -stringValue on NSNumber


  • Subject: Re: unrecognized selector error when calling -stringValue on NSNumber
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 6 Dec 2009 18:52:03 -0800

On Dec 6, 2009, at 15:58, Mazen M. Abdel-Rahman wrote:

> NSNumber * primaryLanguageNumber = [self primaryLanguageID];
> NSString * primaryLanguageString = [primaryLanguageNumber stringValue];
>
> primaryLanguageID is of type NSNumber.  When I am stepping through the debugger I can see the variable primaryLanguageNumber being set correctly. However, once I try to call stringValue on it I get the following error:
>
> 2009-12-06 16:51:24.525 Averroes[21013:a0f] -[NSCFString stringValue]: unrecognized selector sent to instance 0x1001d8a70
>
> Doesn't that mean that it thinks primaryLanguageNumber is a string?  And why would it see it as a string?

It's seeing it as a string because it *is* a string. That is precisely what the error message is telling you -- that the class of the receiver is NSCFString instead of whatever you intended it to be.

There's one fairly obvious scenario that causes this to happen. If you have a text field that modifies the primaryLanguageID property via a binding, and you edit the text field, then the new value will be a NSString regardless of whether the original value was a NSNumber (or anything else). If you  want the modified property to be kept as a NSNumber, you must put a numeric formatter on the text field. (Or, if it's part of a table view, then you must put a numeric formatter on the column's text field cell.) (Or, write a setter for the primaryLanguageID property that takes a NSString parameter but stores a NSNumber in the instance variable.)


_______________________________________________

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

References: 
 >unrecognized selector error when calling -stringValue on NSNumber (From: "Mazen M. Abdel-Rahman" <email@hidden>)

  • Prev by Date: Re: unrecognized selector error when calling -stringValue on NSNumber
  • Next by Date: Re: Best way to hook into the run loop?
  • Previous by thread: Re: unrecognized selector error when calling -stringValue on NSNumber
  • Next by thread: Draw rounded NSImage
  • Index(es):
    • Date
    • Thread