title: How to compare two NSMutableArrays?
body: <p>I'm new to iOS development and having trouble comparing two <code>NSMutableArray</code>. </p>
  
  <p>One of them (<code>appDelegate.array</code> in code) contains data coming from a database and another one (<code>dataArray</code> in code) contains data coming from a server response. </p>
  
  <p>Now I want compare each element of (<code>dataArray</code>) with whole (<code>appDelegate.array</code>) and if some element of (<code>dataArray</code>) exist in (<code>appDelegate.array</code>) then do nothing or break and if doesn't exist then add it into database. </p>
  
  <p>I tried, but am unable to do this. Below is the code I'm using. </p>
  
  <p>Thank you in advance.</p>
  
  <pre><code>NSMutableArray *dataArray = [responseDictionary objectForKey:@"myDATA"];
  
  NSLog(@"%d dataArray count", [dataArray count]);
  
      for (int i = 0; i &lt; [dataArray count]; i++)
      {   
          NSLog(@"%d delegate array count",[appDelegate.array count]);
  
          NSInteger ID = [[[dataArray objectAtIndex:i] objectForKey:@"ID"] intValue];
          NSString *Note = [[dataArray objectAtIndex:i] objectForKey:@"Note"];
          NSString *Reminder = [[dataArray objectAtIndex:i] objectForKey:@"Reminder"];
          NSInteger Status = [[[dataArray objectAtIndex:i] objectForKey:@"Completed"]intValue];
          NSInteger DisplayOrder = [[[dataArray objectAtIndex:i] objectForKey:@"Display_Order"] intValue];
  
          if ([appDelegate.array count] == 0 &amp;&amp; Note != nil) 
          {
              NSString *query = [NSString stringWithFormat:@"INSERT INTO Tasks (Note, Reminder, Status, DisplayOrder) VALUES ('%@','%@','%d','%d')",Note, Reminder, Status, DisplayOrder];
  
              //NSLog(@"%@",query);
              sqlite3 *database_1;
  
              NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
              NSString *documentsDir = [documentPaths objectAtIndex:0];
              NSString *database_Path = [documentsDir stringByAppendingPathComponent:@"TODO.sqlite"];
  
              if(sqlite3_open([database_Path UTF8String], &amp;database_1) == SQLITE_OK)
              {
                  sqlite3_stmt *compiledStatement_1;
                  if(sqlite3_prepare_v2(database_1,[query UTF8String], -1, &amp;compiledStatement_1, NULL) == SQLITE_OK)
                  {
                      while(sqlite3_step(compiledStatement_1) == SQLITE_ROW)
                      {
                          sqlite3_step(compiledStatement_1);
                      }
                  }
                  sqlite3_finalize(compiledStatement_1);
              }
              sqlite3_close(database_1);
  
              [self readDataFromDatabase];
          }
  
          else 
          {
             // NSLog(@"Entered Else");
  
              for (int k = 0; k &lt; [appDelegate.array count]; k++) 
              {
  
  
              objectData = [appDelegate.array objectAtIndex:k];
                //  NSLog(@"%d",objectData.ID);
  
                  NSMutableArray *IDArray = [NSMutableArray arrayWithObject:[[NSNumber numberWithChar:objectData.ID]stringValue]];
                  NSMutableArray *NoteArray = [NSMutableArray arrayWithObject:objectData.Note];
                  NSMutableArray *ReminderArray = [NSMutableArray arrayWithObject:objectData.Reminder];
                  NSMutableArray *StatusArray = [NSMutableArray arrayWithObject:[[NSNumber numberWithChar:objectData.Status]stringValue]];
                  NSMutableArray *DisplayOrderArray = [NSMutableArray arrayWithObject:[[NSNumber numberWithChar:objectData.DisplayOrder]stringValue]];
  
                  NSLog(@"%@ server",[NSString stringWithFormat:@"%d",ID]);
                  NSLog(@"%@ database",IDArray);
  
                  if ([CommonFunctions isValueInArray:[NSString stringWithFormat:@"%d",ID]:IDArray] &amp;&amp; [CommonFunctions isValueInArray:Note :NoteArray] &amp;&amp; [CommonFunctions isValueInArray:Reminder :ReminderArray] &amp;&amp; [CommonFunctions isValueInArray:[NSString stringWithFormat:@"%d",Status] :StatusArray] &amp;&amp; [CommonFunctions isValueInArray:[NSString stringWithFormat:@"%d",DisplayOrder] :DisplayOrderArray]) 
                  {
                      NSLog(@"Present In appDelegate.array!!!");
                  }
                  else 
                  {
                      NSString *query = [NSString stringWithFormat:@"INSERT INTO Tasks (Note, Reminder, Status, DisplayOrder) VALUES ('%@','%@','%d','%d')",Note, Reminder, Status, DisplayOrder];
  
                      NSLog(@"%@",query);
                      sqlite3 *database_1;
  
                      NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                      NSString *documentsDir = [documentPaths objectAtIndex:0];
                      NSString *database_Path = [documentsDir stringByAppendingPathComponent:@"TODO.sqlite"];
  
                      if(sqlite3_open([database_Path UTF8String], &amp;database_1) == SQLITE_OK)
                      {
                          sqlite3_stmt *compiledStatement_1;
                          if(sqlite3_prepare_v2(database_1,[query UTF8String], -1, &amp;compiledStatement_1, NULL) == SQLITE_OK)
                          {
                              while(sqlite3_step(compiledStatement_1) == SQLITE_ROW)
                              {
                                  sqlite3_step(compiledStatement_1);
                              }
                          }
                          sqlite3_finalize(compiledStatement_1);
                      }
                      sqlite3_close(database_1);
  
  
                  }
          }
  
      }
  </code></pre>