Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: NSSortDescriptor not working with array of custom classes (From: Ken Tozier <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.