sorting structures

adamfenn28's picture

I've read many posts and external references that talk about how NSDictionaries can't be sorted. This is troubling. I've noticed that all of the structures outputs my my patches seem to be keyed structures. When I look at the structure on the output port, I see the key surrounded by double quotes. When I look at indexed structures, the index is surrounded by parenthesis. I'm not sure how to create indexed structures with the Official API, and if I could, I'm not sure they would be any better sorted. Would they? If so, how can I index NSDictionaries rather than key them?

The other path I've considered, is that structure's must be sortable. The Structure Sort patch does it. I could settle and just use that patch for my sorting needs, but I'd like to sort in ways that patch won't easily allow me to do. For example, I'd like to sort numerically, and I'd like to sort by the key name. How does the Structure Sort patch do it?

Thanks! Adam

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

franz's picture
Re: sorting structures

Indexed structures are NSArrays, keyed structures are NSDictionary.

adamfenn28's picture
Re: sorting structures

thanks @franz!

I've read through the patch programming guide several times, and it only lists Structures as being NSDictionaries. That's kinda irritating!