• 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: Objects not being added to array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objects not being added to array


  • Subject: Re: Objects not being added to array
  • From: "Matthew Callis" <email@hidden>
  • Date: Sun, 17 Dec 2006 10:42:32 -0600

The array 'allTapes' has a whole list of ID3 tag data taken from a folder of
files, mostly of one album with 1 track from another for testing. What I
want the code to do is go through all that metadata (one for each file I've
already scanned) and check it against the one before it (it's already been
sorted) to see if it is a new album; if it is a new album it should add it
to the new array, if it isn't it should not added it but add up the count
for that album and add it's length (in seconds) to the previous album that
is already started.
It's doing this, but it's adding the album everytime it sees a new item
instead of only the times it needs to be added up, like the output shows it
going from 1 track to 10 and adding the time, I just want the last item with
total tracks and total time.

On 12/17/06, Daniel Jalkut <email@hidden> wrote:

You sure do have a lot of code there. If I try to summarize your problem, I think it's:

It looks like you think allTapes has two items in it, but it actually
has lots of items in it.  Possible? You should check this first by
looking at the value of [allTapes count].

Daniel

On Dec 17, 2006, at 10:36 AM, Matthew Callis wrote:

> That special case does start adding it, but it shows me that the code
> doesn't do what I inteded to do.
> With this code below I expected this output:
> ("The Arcade Fire", "Neon Bible", None,  Indie, 2007, 254,  1,
>  "The Arcade Fire",  Funeral, None, Indie, 2004, 2840, 10)
>
> but instead it is listing every track and adding as it goes.
>
> ("The Arcade Fire", "Neon Bible", None,  Indie, 2007, 254,  1,
>  "The Arcade Fire",  Funeral, None, Indie, 2004, 240, 1)
>  "The Arcade Fire",  Funeral, None, Indie, 2004, 480, 2)
>  "The Arcade Fire",  Funeral, None, Indie, 2004, 840, 3)
> ...
>  "The Arcade Fire",  Funeral, None, Indie, 2004, 2840, 10)
>
> The Code:
>    NSString *cur_artist =     [[allTapes objectAtIndex:0]
> objectAtIndex:0];
>    NSString *cur_venue =     [[allTapes objectAtIndex:0]
> objectAtIndex:1];
>    NSString *cur_location = [[allTapes objectAtIndex:0]
> objectAtIndex:2];
>    NSString *cur_genre =     [[allTapes objectAtIndex:0]
> objectAtIndex:3];
>    NSString *cur_year =     [[allTapes objectAtIndex:0]
> objectAtIndex:4];
> //  NSString *cur_length =     [[allTapes objectAtIndex:0]
> objectAtIndex:5];
>    int cur_length = 0;
>    int cur_count = 0;
>
>    NSMutableArray * tapeBunch = [[NSMutableArray alloc] init];
>    tapeBunch = [[tapeBunch retain] autorelease];
>
>    int allofthem = [allTapes count];
>    for(i = 0; i < allofthem; i++){
>        NSComparisonResult artistResult, venueResult;
>        artistResult = [[[allTapes objectAtIndex:i] objectAtIndex:0]
> compare:cur_artist];
>        venueResult = [[[allTapes objectAtIndex:i] objectAtIndex:1]
> compare:cur_venue];
>
>        if(artistResult != NSOrderedSame || venueResult !=
> NSOrderedSame ||
> i == 0){
>            cur_artist        = [[allTapes objectAtIndex:i]
> objectAtIndex:0];
>            cur_venue        = [[allTapes objectAtIndex:i]
> objectAtIndex:1];
>            cur_location    = [[allTapes objectAtIndex:i]
> objectAtIndex:2];
>            cur_genre        = [[allTapes objectAtIndex:i]
> objectAtIndex:3];
>            cur_year        = [[allTapes objectAtIndex:i]
> objectAtIndex:4];
>            cur_length        = [[[allTapes objectAtIndex:i]
> objectAtIndex:5] intValue];
>            cur_count        = 1;
>        }
>        else{
>            cur_count++;
>            cur_length        += [[[allTapes objectAtIndex:i]
> objectAtIndex:5] intValue];
>        }
>        [tapeBunch addObject:cur_artist];
>        [tapeBunch addObject:cur_venue];
>        [tapeBunch addObject:cur_location];
>        [tapeBunch addObject:cur_genre];
>        [tapeBunch addObject:cur_year];
>        [tapeBunch addObject:[NSString stringWithFormat:@"%i",
> cur_length]];
>        [tapeBunch addObject:[NSString stringWithFormat:@"%i",
> cur_count]];
>    }
>    NSLog(@"tapeBunch:\n %@", tapeBunch);
> --
> - 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:
> sweater.com
>
> This email sent to email@hidden




-- - 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


References: 
 >Objects not being added to array (From: "Matthew Callis" <email@hidden>)
 >Re: Objects not being added to array (From: Daniel Jalkut <email@hidden>)

  • Prev by Date: Re: Objects not being added to array
  • Next by Date: Re: NSScrollView custom thumbs
  • Previous by thread: Re: Objects not being added to array
  • Next by thread: Re: Objects not being added to array
  • Index(es):
    • Date
    • Thread