Re: Objects Not being added to array
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 01:24:45 -0600
Thanks Nick & Andrew! That fixed the math problem, and for time's sake I
haven't changed to keyed values yet, but the main problem still exist that
the first item in my array isn't added due to flawed logic that I can't seem
to figure out in Objective-C that was done in C++.
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];
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 != 0 || venueResult != 0){
[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]];
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];
}
}
I cannot for the life of me get the first item in the array listed and use
it at the same time to compare it to the next, and when it is set to nil it
throws an error when trying to add an empty object to the array. My other
thoughts throw an out of bounds error.
--
- 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