Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ahan.tm

macrumors regular
Original poster
Jun 26, 2011
141
0
Florida
Hi,

I have an array and I need to find if 2 records are the same. I have this code so far, but it cannot tell me at which index number they are the same.

Code:
Code:
marbelesreached = NO;
    for(int i=0; i< [records count] ; i++){
        if ([[[records objectAtIndex: i] valueForKey: @"marbles"] intValue] == [[[records objectAtIndex: i]valueForKey:@"marblesneeded"] intValue]) {
            marbelesreached = YES;
            break;
        }
    }

What is the code to find out which index number is equal.

Thanks
 

North Bronson

macrumors 6502
Oct 31, 2007
395
1
San José
What version of the OS are you supporting? Before you start doing this work with for-loops, try looking through the block-based enumerators. Do you see how a method like indexOfObjectPassingTest: might give you the functionality that you need?

Also, is there a reason that you need to use valueForKey: instead of a custom accessor method? Are you using custom objects?
 

ahan.tm

macrumors regular
Original poster
Jun 26, 2011
141
0
Florida
Okay, i figured it Out:

Here is the code:

Code:
for(int i=0; i< [records count] ; i++){
        if ([[[records objectAtIndex: i] valueForKey: @"marbles"] intValue] == [[[records objectAtIndex: i]valueForKey:@"marblesneeded"] intValue] && [[[records objectAtIndex: i]valueForKey:@"marblesneeded"] intValue]!= 0) {
            [[records objectAtIndex:i] valueForKey: @"prizereached"] = YES;
        }
    }

This might change if something else changes:)

Thanks
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.