Re: setNumberOfObjects in an NSArray [SOLVED]
Re: setNumberOfObjects in an NSArray [SOLVED]
- Subject: Re: setNumberOfObjects in an NSArray [SOLVED]
- From: Dev WO <email@hidden>
- Date: Wed, 3 Aug 2005 02:06:29 +0200
Hi LD,
sorry I didn't mentioned it clearly, but I reworked my design the way
David suggest to manage the array directly from the fetch specification.
So I didn't need to limit the array programmatically.
But thank you for the tips, I'll mark that message to make sure I've
got something if I have to deal with this problem again:)
Xavier
Le 3 août 05 à 01:54, LD a écrit :
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