How can I test for NSArray


(Doeke Zanstra) #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?


(Shane Stanley) #2

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.


(Doeke Zanstra) #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).)


(Shane Stanley) #4

Yes, valueForKey: always returns Cocoa objects. With dictionaries, you would usually use objectForKey:.


(Doug Adams) #5

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