Class "ClassName" vs. current application's ClassName

When I started using AppleScriptObjC years ago, a commonly used way to refer to Cocoa classes was the following:

property NSString : class "NSString"
property NSFileManager : class "NSFileManager"

That’s the method I’m still using and it works with no issues, as far as I can tell.

However, these days all I see in code examples is this:

property NSString : reference to current application's NSString
property NSFileManager : reference to current application's NSFileManager

I prefer the class "ClassName" approach for brevity sake.

But I started wondering if I’m missing something and if there are any pitfalls or potential disadvantages in this approach?

I looked through Apple’s docs on the subject - but, frankly, I couldn’t understand if there’s any difference in practical terms: Mac Automation Scripting Guide: Objective-C to AppleScript Quick Translation Guide

Like I mentioned, class "ClassName" seems to work for me in any situation.

If anyone has any insights on this or case scenarios where these two approaches are not interchangeable, it will be appreciated!

1 Like

Both work fine. Many years ago one of the AS engineers told me the variable method was preferred, but gave no reason why.

One advantage of the variable method is that you can take advantage of code-completion in Script Debugger. That in turn means less risk of typos.

3 Likes

Thanks Shane, that’s exactly the info I was looking for.