FROM : Shawn Erickson
DATE : Fri May 16 08:05:18 2008
On Thu, May 15, 2008 at 10:43 PM, Kyle Sluder
<kyle.sluder+<email_removed>> wrote:
> On Thu, May 15, 2008 at 5:30 PM, <<email_removed>> wrote:
>> It would seem that NSDictionaryController keys have to be strings.
>
> Yes. It is very common that, despite NSDictionary accepting any
> object as a key, you must use NSString keys.
>
>> So the sorting of numeric string keys is always going to be alphabetic.
>
> Not true. See -[NSString compare:options:] with the NSNumericSearch option.
>
>> My solution was to discard NSDictionaryController and create a proxy object
>> containing two properties:
>
> I would instead suggest subclassing NSDictionaryController and
> overriding -arrangedObjects. The naive implementation would call
> super's implementation and return a sorted version of the result. The
> published interface says that -arrangedObjects returns id, but the
> documentation says that it returns an array, so I would feel
> reasonably safe treating the return value as an NSArray.
Consider using the built in sort facility...
<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSArrayController_Class/Reference/Reference.html#//apple_ref/occ/instm/NSArrayController/setSortDescriptors:>
<http://developer.apple.com/documentation/Cocoa/Conceptual/SortDescriptors/Concepts/Creating.html>
-Shawn
DATE : Fri May 16 08:05:18 2008
On Thu, May 15, 2008 at 10:43 PM, Kyle Sluder
<kyle.sluder+<email_removed>> wrote:
> On Thu, May 15, 2008 at 5:30 PM, <<email_removed>> wrote:
>> It would seem that NSDictionaryController keys have to be strings.
>
> Yes. It is very common that, despite NSDictionary accepting any
> object as a key, you must use NSString keys.
>
>> So the sorting of numeric string keys is always going to be alphabetic.
>
> Not true. See -[NSString compare:options:] with the NSNumericSearch option.
>
>> My solution was to discard NSDictionaryController and create a proxy object
>> containing two properties:
>
> I would instead suggest subclassing NSDictionaryController and
> overriding -arrangedObjects. The naive implementation would call
> super's implementation and return a sorted version of the result. The
> published interface says that -arrangedObjects returns id, but the
> documentation says that it returns an array, so I would feel
> reasonably safe treating the return value as an NSArray.
Consider using the built in sort facility...
<http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSArrayController_Class/Reference/Reference.html#//apple_ref/occ/instm/NSArrayController/setSortDescriptors:>
<http://developer.apple.com/documentation/Cocoa/Conceptual/SortDescriptors/Concepts/Creating.html>
-Shawn
| Related mails | Author | Date |
|---|---|---|
| jonathan@mugginsof… | May 13, 13:25 | |
| jonathan | May 15, 23:30 | |
| Kyle Sluder | May 16, 07:43 | |
| Shawn Erickson | May 16, 08:05 | |
| jonathan@mugginsof… | May 16, 14:03 | |
| jonathan@mugginsof… | May 16, 14:07 |






Cocoa mail archive

