doekman
(Doeke Zanstra)
February 12, 2019, 8:37am
#1
I want test if a variable is a list (otherwise it’s probably a string). I did this like this:
if class of my_variable is list then
...
end if
However, because of reasons (the list is inside a record, and I casted it to an NSDictionary so I could easier work with it), it’s an NSArray.
How do I test for this?
If you know it’s a Cocoa object, you can do ths:
my_variable's isKindOfClass:(current application's NSArray)
If you want to know if its an array or list, just converting it to one or the other.
doekman
(Doeke Zanstra)
February 13, 2019, 1:02pm
#3
OK. That works.
When I do a valueForKey:
on a NSDictionary
, do I always get a Cocoa object back in AppleScript? (Apple’s Objective-C’s API documentation says (ObjectType)
.)
Yes, valueForKey:
always returns Cocoa objects. With dictionaries, you would usually use objectForKey:
.
1 Like
DougAdams
(Doug Adams)
February 14, 2019, 12:19pm
#5
Probably should always coerce objectForKey:
returns to the AS type you’re expecting