• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSortDescriptor not working with array of custom classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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

  • Prev by Date: Re: [C++ & Cocoa] [was:Cocoa developer needed in Texas]
  • Next by Date: Re: Question Mark Cursor
  • Previous by thread: Re: NSSortDescriptor not working with array of custom classes
  • Next by thread: Getting list of classes inside NSBundle
  • Index(es):
    • Date
    • Thread