Re: How Do I Handle NSNumber Returned in ASObjC?
Re: How Do I Handle NSNumber Returned in ASObjC?
- Subject: Re: How Do I Handle NSNumber Returned in ASObjC?
- From: Shane Stanley <email@hidden>
- Date: Mon, 13 Jun 2016 10:04:47 +1000
On 13 Jun 2016, at 9:37 AM, Jim Underwood <email@hidden> wrote:
>
> ASObjC returns a class of "NSNumber" (actually, Script Debugger reports the class as "(Class) __NSCFNumber"). I need to convert that into an AppleScript number, but integer or real?
First, there's no guarantee it will be an __NSCFNumber -- that's just one of several possible subclasses of NSNumber it could be. Rather than get the class, you check for any subclass like this:
if (theResult's isKindOfClass:(current application's NSNumber)) as boolean then
That checks if it's any subclass of NSNumber.
But the real/integer/boolean problem (and more) can be solved without any of that. Rather, you can let the scripting bridge do the work for you. So after you have checked for missing value:
set theResult to theDict's objectForKey:pKeyStr
set someArray to current application's NSArray's arrayWithObject:theResult
return item 1 of (someArray as list)
What this does is makes a single-item array containing theResult. When that's converted to an AppleScript list, the item within it will also be converted to an AppleScript item if it can. So this covers all the bridgeable AS classes -- text, numbers, lists, records, whatever. You then extract the item from the list.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden