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