0

Given a scriptable object's NSScriptObjectSpecifier, how do I tell the index of object(s) in their container?

I cannot find any accessor method for that in the NSScriptObjectSpecifier or its subclasses.

If the object is a NSIndexSpecifier, it's easy to get the index. But if it's something else, e.g. a NSNameSpecifier, then it needs to be inquired. The Cocoa Scripting guide says that the framework does that automatically when it needs to learn the index, but it's not explained how that's done.

There is the method indicesOfObjectsByEvaluatingObjectSpecifier a scriptable object can implement to return such indices, but that's an optional method, and so I assume I cannot simply invoke that on any scriptable object.

Is there some other easy way to learn the index, or do I have to implement my own method that walks down the specifiers and handles all the possible cases on its own?

6
  • Have you implemented -objectIn<Key>AtIndex:? Commented May 15, 2016 at 13:08
  • Yes. How would that help? I don't want to have to get all items and then search them for the object in question. That'd lead to quite a bad performance. Commented May 15, 2016 at 13:21
  • Then I don't understand the question. For any subclass in the hierarchy you have to provide a NSScriptObjectSpecifier containing the containerClassDescription. From that specifier the framework can identify the proper index. Commented May 15, 2016 at 14:46
  • I need the inverse function: I know the specifier and want to know its index, thru Cocoa Scripting. As the specifier may point to any number of different classes, I cannot query the objects directly unless I'd extend each of them with my own protocol to return their index in their container. That's overkill, IMHO. I need this in order to be able to tell if an array of such specifiers is in order (needed for creating NSRangeSpecifier, see stackoverflow.com/questions/37239287), though the suggestion in your 1st comment would help identifying the indices, but it'll be slow with large lists Commented May 15, 2016 at 15:43
  • @vadian If you put your comment into an answer, I'll upvote it (though it won't be the accepted answer because it doesn't answer the question completely, i.e. how to return a non-consecutive list). Commented May 15, 2016 at 15:48

1 Answer 1

0

Are you looking for NSArray's

- indexOfObjectIdenticalTo:self

by any chance? I use this in an -objectSpecifier method when I need to return a formIndex ospec.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.