Re: NSSortDescriptor not working with array of custom classes
Re: NSSortDescriptor not working with array of custom classes
- Subject: Re: NSSortDescriptor not working with array of custom classes
- From: Keary Suska <email@hidden>
- Date: Fri, 19 Oct 2007 17:10:19 -0600
- Thread-topic: NSSortDescriptor not working with array of custom classes
on 10/19/07 12:04 PM, email@hidden purportedly said:
> I managed to get it working but don't know why this fails
>
> - (id) pageNumber
> {
> return [pagePropertiesDict objectForKey: @"page_number"]; // returns
> an NSNumber
> }
>
> NSArray *sortDescriptors = [NSArray arrayWithObject:
> [[NSSortDescriptor alloc] initWithKey: @"pageNumber" ascending: YES]]];
>
> [selectedPages: sortUsingDescriptors: sortDescriptors];
>
> ------------------------------------------------------------------------
> ----
> While this works
>
> - (id) valueForKey:(NSString *) inKey
> {
> return [pagePropertiesDict objectForKey: inKey];
> }
>
> NSArray *sortDescriptors = [NSArray arrayWithObject:
> [[NSSortDescriptor alloc] initWithKey: @"page_number" ascending: YES]]];
>
> [selectedPages: sortUsingDescriptors: sortDescriptors];
>
> I understand why the bottom works but can anyone explain why the top
> fails? Seems like it should work...
Generally when KVC/KVO is involved, things rarely "just don't work". Is
there an exception occurring that you aren't telling us, or are you possibly
trapping exceptions and ignoring them?
In ay case, you should probably be using the following:
NSArray *sortDescriptors = [NSArray arrayWithObject:
[[NSSortDescriptor alloc] initWithKey: @"pagePropertiesDict.page_number"
ascending: YES]]];
Presuming, of course, that pagePropertiesDict is a KVC compliant property.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden