Search code examples
iphoneipadcomparensindexpath

comparing indexPaths in a loop iphone


I am trying to compare an index path in my didSelectRowAtIndexPath delegate method with an array of index paths.

for (n=0; n < [tempMutArrray count]; n= n+1){

     NSComparisonResult *result = [indexPath compare:[tempMutArray objectAtIndex:n];

//What I want to do is is write an if statement that executes a certain block of code 
//if the two index paths are equal, but I cant figure out how to work with an 
//NSComparisonResult. 

} 

Solution

  • Use NSOrderedSame and no pointer - NSComparisonResult is just an integer:

    NSComparisonResult result = [indexPath compare:[tempMutArray objectAtIndex:n];
    
    if(result == NSOrderedSame) {
        // do stuff
    }
    

    In the Cocoa APIs, there are some non-class-types in use. Most important are those from the Foundation data types, which include

    • enumerations
    • typedefs for integral types
    • structures