0

I'm trying to find if paket2 contains any object from paket1. I tried this code:

//assume paket1 and paket2 are 2 NSArrays
            int n;
            int m;
            for (n=0; n<[paket1 count]; n++) {
                for (m=0; m<[paket2 count]; m++) {
                    if (paket1[n]==paket2[m] ) {
                        NSLog(@"some message");
                    }else{
                        NSLog(@"bruhuhuhu");
                    }
                }
            }

but I have a feeling that == operator just checks if 2 memory adresses are equal. I would like to check values of array objects. Can you guys direct me how to do it?

potato
  • 4,479
  • 7
  • 42
  • 99

2 Answers2

2

Use isEqual:

        for (int n=0; n<paket1.count; n++) {
            for (int m=0; m<paket2.count;m++) {
                if (paket1[n] isEqual: paket2[m] ) {
                    NSLog(@"some message");
                }else{
                    NSLog(@"bruhuhuhu");
                }
            }
        }
Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
  • You can also refer to this question : http://stackoverflow.com/questions/7229046/compare-two-arrays-and-put-equal-objects-into-a-new-array – Teja Nandamuri Mar 03 '15 at 16:15
1

Assuming that the objects inside array have the isEqual: method implemented:

[paket1[n] isEqual:paket2[m]]
Aris
  • 1,529
  • 9
  • 17