Re: for Loop Error or Logical Error?
Re: for Loop Error or Logical Error?
- Subject: Re: for Loop Error or Logical Error?
- From: Nir Soffer <email@hidden>
- Date: Sun, 24 Dec 2006 19:05:25 +0200
On Dec 23, 2006, at 22:23, Matthew Callis wrote:
I have a loop that is going through an array of sorted items and
making a
list of the unique items while counting the instances of them. The
error
occurs in that the last unique set of items in the array is not being
counted or listed, even though It IS in the array. The output
should have 3
items, not 2.
[snipped long-complex-error-prone-code-with-billion-temporary-
variables]
Read first file:///Developer/ADC Reference Library/documentation/
Cocoa/Conceptual/Collections/index.html.
According to the description above, you can do this:
// Assume that tapes is sorted array
NSSet *uniqueTapes = [NSSet setWithArray:tapes];
You can get the count of items with [uniqueTapes count];
If you want a sorted list, implement compare: in Tape, and do this:
NSArray *sortedUniqueTapes = [[uniqueTapes allObjects]
sortedArrayUsingSelector:@selector(compare:)];
According to your code, you want to format a tab delimited list of
the unique items. Why do you want such list - it this a way to export
the data or a way to show the results?
Best Regards,
Nir Soffer
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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