Re: how to simulate passing parameter with selector
Re: how to simulate passing parameter with selector
- Subject: Re: how to simulate passing parameter with selector
- From: Graham <email@hidden>
- Date: Thu, 14 Feb 2008 12:46:00 +1100
How about just using sortUsingFunction:context: and pass your field
index in <context>. That simply gets passed uninterpreted to your
compare function which can then use that index to pull the field from
the record.
If you need more context just bundle it into a struct.
------
S.O.S.
On 14/02/2008, at 12:36 PM, Daniel Child wrote:
I'm sorry, but looking at the documentation I don't see how using
NSSortDescriptor works. Their example uses keys for the instances
of a custom class (employee age / hire date, etc.). All I have is a
generic class. The structure of a GenericRecord is
@interface GenericRecord : NSObject
{
NSMutableArray *record;
int numFields;
}
and the fields are inside of the record ivar. My GenericTable class
contains an instance variable "records" (an array) that holds a
collection of these generic records. As far as I can tell, KVC
doesn't apply. TI am not trying to sort the records by "numFields"
or by "record" (for which I could use KVC). I want to sort them
according to field i within the record.
My comparison method should be something like this:
- (NSComparisonResult) compareRecord: (GenericRecord *) gr byField:
(int) fieldNumber;
By definition, this kind of method has arguments and cannot go be
passed as a selector. (OR CAN IT?)
As they say at the end of the chapter, "Each object in the
collection must be key-value coding-compliant for the property key
used to
create the sort descriptor ." And it needs to use a compare: method
which, if specified, also employs a selector. I'm left with the
same problem I had before: no way to compare on a particular index
of the array.... If I've missed something, please let me know. Thanks.
On Feb 13, 2008, at 5:12 PM, Hamish Allan wrote:
On Feb 13, 2008 8:51 PM, Daniel Child <email@hidden> wrote:
Is there a way around this?
Use an NSSortDescriptor (you can specify the sort key, the sort
direction and the comparison selector separately).
Best wishes,
Hamish
_______________________________________________
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:
40ictinternational.com.au
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