Test class of object

I need to test if a value is text or a number.

...
...
set theStat to theDict's objectForKey_(theKey)
if class of theStat is number then 
	set theStat to thousands's stringFromNumber_(theStat)
end if
return theStat

when logged, the class of theStat is __NSFCNumber. When I try to test for number or real or NSNumber or even __NSFCNumber it never tests true. How do I test the class?

Thanks in advance,
Brad

Perhaps you can check for objectAtIndex_(0)'s isKindOfClass__(current application’s NSString) by running an if statement to validate if the object is a number or any other character. It can be easily done in appleScript by comparing the object to a predefined values.

I am working on a similar problem and will ask for help if I fail to resolve it.

t.

Try this (untested):

set theStat to theDict's objectForKey_(theKey)
if theStat's |class()| is current application's NSNumber then 
   set theStat to thousands's stringFromNumber_(theStat)
end if
return theStat

But basically, if you need to return an NSString, the stringFromNumber will try to do convert it to a string, even if it’s already a string.

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

Use something like this:

set theStat to theDict's objectForKey_(theKey)
if (theStat's isKindOfClass_(current application's NSNumber)) as boolean then
	set theStat to thousands's stringFromNumber_(theStat)
end if
return theStat

By using isKindOfClass_ you find out whether it’s a member of the class or one the class’s subclasses.

Thanks for that. By what I was getting the in the console, from my log statements, I should have pointed me in the direction of “current application’s…”

I did discover that stringFromNumber_ “converts” strings–it would return “missing value” and that was not what I wanted.:lol:

Thanks again,
Brad