Selection property

What’s the best way to implement a “selection” property in a class? In my case, it always refers to a list of selected objects, and they will always be of class “asset”. I also want to be able to do “set someProperty of selection”, where someProperty is a property of “asset”.

Do I need to make an actual Objective-C class for a Selection object, then handle each property and command that “asset” handles? Or is there an easier way?

@alldritt used to have a blog post on implementing a selection property — maybe he will pipe up.

I presume you are implementing this using Cocoa Scripting.

Implementing a selection property is fairly simple. If the selection property is application global, add a selection property definition to the application object in your SDEF. If the selection is per-document, then add it to your document object in your SDEF.

The selection property should indicate that its value is a list. The data type can be any or if the value is always going to be an asset then use that data type.

As for being able to manipulate the referenced asset objects through the selection property, you’ll need to extend Cocoa Scripting to support this. Out of the box, Cocoa Scripting does not support property-of-property or array-reference-of-property object specifiers.

I think @ShaneStanley is referring to this post which does not really explain how to implement a selection property in a general sense.

Yes, it’s using Cocoa scripting. I know how to add the selection property, it’s the implementation that has me stumped. Do I implement the selection as its own object in Cocoa, and then it handles the “get” and “set” verbs? That’s how we did it way back in Carbon land.

Sorry for the delay in responding.

For FaceSpan, I did it using a simple property that returned a list of object references and then hacked Cocoa Scripting’s object resolution to allow property-of-property access throughout the application’s object model.

Both approaches (as a simple property returning a list of object references, and an object with properties) can be made to work.

I’m going to have to dig up the old FaceSpan code to figure out how I did this. I’ll get back to you when I find the code I used and can factor it into something you can employ.

Had any time to look into this? I’ve been messing with all the different Cocoa scripting classes, trying to find some combination of junk that works, but no luck so far. This is such a common thing that an app would do, I’m surprised Apple didn’t document how to go about it.