Search code examples
iphoneipadnsmutablearraynsarraycompare

Compare two NSMutableArray indices in iPhone


I want to compare two array indices,

for (int i=0; i<[CustomeDateArray count]; i++)
  {
      if (([CustomeDateArray objectAtIndex:1] == [newDateArray objectAtIndex:1]) && ([CustomeDateArray objectAtIndex:2] == [newDateArray objectAtIndex:2]))          
                {
                    exists=TRUE;
                    NSLog(@"exists=TRUE");
                }
  }

My Log shows this Results:

 CustomeDateArray at Index1=06
 CustomeDateArray at Index2=2012
        
 newDateArray at Index1=06
 newDateArray at Index2=2012

If my if condition is true then control should go inside and it should print exists=TRUE but i am unable to see exists=TRUE control is not going inside.

What's the problem?


Solution

  • for (int i=0; i<[CustomeDateArray count]; i++)
      {
              if (([[CustomeDateArray objectAtIndex:1] isEqual:[newDateArray objectAtIndex:1]]) && ([[CustomeDateArray objectAtIndex:2] isEqual:[newDateArray objectAtIndex:2]]))        
                    {
                        exists=TRUE;
                        NSLog(@"exists=TRUE");
                    }
      }