比较目标c中的2个整数数组(移动应用程序)

时间:2011-04-09 16:36:00

标签: arrays cocoa-touch

我正在尝试比较2个阵列,但问题是它们并不是一直相同,即使我给出了2个相同的数组。这将需要奇怪的价值,我不知道他们来自哪里。谁能帮助我并提出解决这个问题的建议?提前谢谢。

这是我的代码:

for (int i =0; i< array1.count; ++i)
    for(int j=0; j< array2.count; ++j)
    {
        NSLog(@"in the loop");
        NSLog(@"array1 1=%d",[array1 objectAtIndex:i]);

        if ([[array1 objectAtIndex:i] isEqual: [array2 objectAtIndex:j]])
        {
            NSLog(@"[array1 objectAtIndex:i] = %@", [array1 objectAtIndex:i]);
            NSLog(@"[array1 objectAtIndex:j] = %@", [array1 objectAtIndex:j]);

            NSLog(@"am in here winner");
            NSLog(@"the same");
            equals++;
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试isEqualToNumber:,甚至比较[[array1 objectAtIndex:i] compare: [array2 objectAtIndex:j]] == NSOrderedSame