How can I test for NSArray

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.

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

Probably should always coerce objectForKey: returns to the AS type you’re expecting