Re: for Loop Error or Logical Error?
Re: for Loop Error or Logical Error?
- Subject: Re: for Loop Error or Logical Error?
- From: "Matthew Callis" <email@hidden>
- Date: Sun, 24 Dec 2006 20:25:41 -0600
The first item is initialized so that it won't be added on the first run
through, it would have a 0 for item count and length, so I set it to compare
the first item and then set it to compare the one it just went through. I
was getting a unique set of tapes but now I want to get a unique set of
albums, all the tapes that belong to an album are counted and have their
length added up and THEN output that when it finds a new track and continue
the process for that track. If the track was set to nothing it would add it
since it doesn't match the current tape.
I've made the readability changed as suggested, thanks for those!
On 12/24/06, Nir Soffer <email@hidden> wrote:
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
--
- Matthew
http://eludevisibility.org/
_______________________________________________
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