ASObjC Singletons question

Just a sanity check, this one.

When using singletons like NSFileManager.default() and NSWorkspace.shared(), is there any reason I shouldn’t do this in the property declaration:

property FileManager : a reference to current application's NSFileManager's defaultManager

As opposed to this:

property NSFileManager : a reference to current application's NSFileManager
set fileManager to NSFileManager's defaultManager()

I note that you can’t add the parens to defaultManager if you include it in the property declaration, and I recall some warnings about omitting those, but unsure whether those would come in to play here.

I’m normally nervous about leaving off parentheses, but I can’t see that problem here. Not that I say that with total confidence.

One thing I do notice, though, is this:

use framework "Foundation"
property fileManager : a reference to current application's NSFileManager's defaultManager

--> defaultManager of NSFileManager

The variable doesn’t contain the pointer, so it presumably has to be resolved each time it occurs. In AEPrint it looks like this:

--> 'obj '{ 'form':'usrp', 'want':'prop', 'seld':'utxt'("defaultManager"), 'from':'obj '{ 'form':'usrp', 'want':'prop', 'seld':'utxt'("NSFileManager"), 'from':null() } }

I wonder whether that going to have some minor performance penalty — or other subtle side-effects.

Yeah, that’s what I noticed, instead of something like

<NSFileManager: 0x60000000f9a0>.

That’s what led me to ask the question. At first, I thought it was a clever shortcut, then I wondered about that value.

OK, better to stick with safe than sorry. :persevere:

Thanks for the feedback, Shane.