• 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: Ken Tozier <email@hidden>
  • Date: Fri, 19 Oct 2007 14:04:47 -0400

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...

Thanks for any help

Ken


On Oct 19, 2007, at 12:33 PM, Ken Tozier wrote:

Hi

I have an NSMutableArray containing instances of a custom "Page" class and can't get NSSortDescriptor to do anything. The page class has an accessor method for the property I want to sort.

- (id) pageNumber
{
	return [pageRecord objectForKey: @"page_number"];
}

In the object that contains the page array, the sort descriptor array is initialized like this

NSArray *sortDescriptors = [NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey: @"pageNumber" ascending: YES]];

And I try to use it like this

NSLog(@"before sorting: %@", selectedPages);

[selectedPages sortUsingDescriptors: sortDescriptors];

NSLog(@"after sorting: %@", selectedPages);

Regardless of the order in which I select pages, the before and after arrays are identical. Anyone see where I'm messing up?

Thanks for any help

Ken
_______________________________________________

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:
40comcast.net


This email sent to email@hidden

_______________________________________________

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


  • Follow-Ups:
    • Re: NSSortDescriptor not working with array of custom classes
      • From: Keary Suska <email@hidden>
References: 
 >NSSortDescriptor not working with array of custom classes (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: Mulit-state buttons
  • Next by Date: Getting list of classes inside NSBundle
  • Previous by thread: NSSortDescriptor not working with array of custom classes
  • Next by thread: Re: NSSortDescriptor not working with array of custom classes
  • Index(es):
    • Date
    • Thread