• 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: setNumberOfObjects in an NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: setNumberOfObjects in an NSArray [SOLVED]
      • From: Dev WO <email@hidden>
References: 
 >setNumberOfObjects in an NSArray (From: Dev WO <email@hidden>)

  • Prev by Date: Re: Reusable Component Tricks...
  • Next by Date: Re: setNumberOfObjects in an NSArray [SOLVED]
  • Previous by thread: Re: setNumberOfObjects in an NSArray
  • Next by thread: Re: setNumberOfObjects in an NSArray [SOLVED]
  • Index(es):
    • Date
    • Thread