Re: Copying Notification Dictonaries & sortingUsingSelector problems
Re: Copying Notification Dictonaries & sortingUsingSelector problems
- Subject: Re: Copying Notification Dictonaries & sortingUsingSelector problems
- From: Andreas Schwarz <email@hidden>
- Date: Wed, 26 Jun 2002 13:19:15 -0700
But when I run the program the following message is logged:
-[NSCalendarDate sortExperiments:]: selector not recognized
The obvious problem is that you're sending the -sortExperiments:
message to a date, not to the array of experimentKeys.
I figured that, but I don't get it, because I'm 100% sure that
experimentKeys is an array, containing NSCalendarDates. So I what I
thought was that the sortExperiments method is triggered with as it's
argument the NSCalendarDates derived from the array. Why then, as the
sortExperiment: function takes an NSCalendarDate, doesn't it work?
The original response was close but not exactly right. You're sending
the sortWithSelector: message to the array correctly, but then what it
does is call that selector (sortExperiments:) on all of it's items.
Those items are NSCalendarDate objects, and the runtime is complaining
that NSCalendarDate does not respond to sortExperiments:. This is
because you implemented sortExperiments: in your Experiment class. If
you want to send this sort message to your *Experiment* objects, you
will need to send it to an array of those objects, not of
NSCalendarDates.
One thing you might want to look at is NSDictionary's
keysSortedByValueUsingSelector: method. This returns an array of the
keys in the dictionary (your NSCalendarDates) in the order they'd be in
based on the sort order of the values (your Experiment objects). In
that case, the message would be sent to your Experiment objects and you
can do what you like with it.
Remember, the message is sent to an Experiment object and another is
sent as the argument for comparison. So your method should look like
this:
- (NSComparisonResult)sortExperiments:(Experiment *)otherExperiment {
return [[self stopdate] compare:[otherExperiment stopdate]];
}
(Simple!)
Andreas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.