Re: setNumberOfObjects in an NSArray
Re: setNumberOfObjects in an NSArray
- Subject: Re: setNumberOfObjects in an NSArray
- From: LD <email@hidden>
- Date: Wed, 3 Aug 2005 09:54:07 +1000
Hi there,
On 03/08/2005, at 4:10 AM, Dev WO wrote:
Does anyone know how to do something like setNumberOfObjects on an
NSArray?
subarrayWithRange not do the trick?
Or maybe I missed something a lot before, for example if I was able
to request a fetch already sorted like the globalDate does it?
You could define a nested comparator class for your entity. e.g.,
public class YourEntity {
<...>
public static class Comparator extends NSComparator {
public int compare(Object object1, Object object2) throws
NSComparator.ComparisonException {
if (object1 instanceof YourEntity && object2 instanceof
YourEntity) {
YourEntity e1, e2;
<...>
if (e1.something() < e2.something()) {
return NSComparator.OrderedAscending;
} else if (e1.something() > e2.something()) {
return NSComparator.OrderedDescending;
}
return NSComparator.OrderedSame;
} else {
throw new NSComparator.ComparisonException("Objects
must be of type YourEntity!");
}
}
}
}
and use like so for in-memory sorting:
NSComparator comparator = new YourEntity.Comparator();
someMutableArray.sortUsingComparator(comparator); // or...
someimmutableArray = someArray.sortedArrayUsingComparator(comparator);
Utilising NSKeyValueCoding's valueForKeyPath may be of help here too
on getting back an array of timestamps from your entity array. i.e.,
your aim is to quickly and efficiently find the index of the last
object in the array that fits your criteria. Once you've got the
index you can build your NSRange...
with regards,
--
LD
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden