In addition the great answer of Alan, I want to add that you should be really careful about using SortedCollections, because adding is much slower than in other collections. So....what yo can do, depending on your needs, is to use a OrderedCollection or similar, and then, when you need it to be sorted, you use the message #asSortedCollection: cheers mariano On Sat, Dec 11, 2010 at 11:27 PM, Alan Rodas <alanrodas@gmail.com> wrote:
The problem seams to be the kind of collection you are using.
A SortedCollection holds elements sorted by a given criteria (In the form of a block). When you add elements to an instance of SortedCollection, the rule is execute with the new object added, and the contained object to determinate the object position. Now, the at: put: message in this kind of collections (SortedCollection is a specific class of OrderedCollection), is used to put an object instead of another. But in a SortedCollection, if you replace an object by other, then you are breaking the sort of the collection. That's why SortedCollection overrides at:put: as self shouldNotImplement, which raises an exception indicating that you send a message that should not be implemented by that object (Although for me, this reflects a bad design in the hierarchy of Collection)
So the possible solutions are: -If what you want is sort the elements by a giving criteria, use add: to add the objects to the collection. -If you want to sort the collection by the order in which you added the elements, use OrderedCollection instead. You should use add: for this to, as at: put: is used to replace an object by another. -If you have a fixed number of elements to add, you should use an Array, you should set the object of the array using at: put:
Hope that helps. And, if I misunderstood you problem, please forgive me.
Cheers -- Alan Rodas Bonjour