我正在尝试比较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++;
}
}
答案 0 :(得分:0)
尝试isEqualToNumber:,甚至比较[[array1 objectAtIndex:i] compare: [array2 objectAtIndex:j]] == NSOrderedSame