0
    BOOL isnot=true;
    for(BGAddressAnnotation * old in oldAnnot){
        if(new.myBiz==old.myBiz){
            //[self animationOutAndInBetweenNew:new andOld:old];
            isnot=false;
        }else{
        }
    }

At first I was confused why my programmer did that rather than just use NSArray containsObject. Then I realized. He's not looking if the object is in an array.

The array is of type BGAddressAnnotation. Each of which contains a reference to myBiz. He wants to know if the biz is contained inn oldAnnot.

Is there a quicker way to do it using say, keyPath, or is his way is indeed the way

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235
Anonymous White
  • 2,149
  • 3
  • 20
  • 27
  • The way he's doing it is pretty fast. Fewer statements is not necessarily "quicker". (Keep in mind that any solution would have to iterate through the array, reference that field, and compare it. The only thing I'd change is to make a copy of new.myBiz rather than fetching it afresh each iteration.) – Hot Licks Oct 31 '12 at 01:52

1 Answers1

1

You could try something as follows, and I'm pretty certain it would be quicker. If not, I at least think it's nicer to look at!

NSArray *oldAnnot = ...
NSArray *oldAnnotBizs = [oldAnnot valueForKeyPath:@"@unionOfObjects.myBiz"];
BOOL isFound = [oldAnnotBizs containsObject:new.myBiz];

Note that I've inverted the meaning of your BOOL variable, because I think you should avoid the use of a double negative (e.g. isFound=YES is nicer than isnot=NO).

Sam
  • 5,892
  • 1
  • 25
  • 27