views:

139

answers:

2

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. 

} 
+1  A: 

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
Georg Fritzsche
+1  A: 

It's just an int holding one of these values:

  • NSOrderedAscending
  • NSOrderedSame
  • NSOrderedDescending

In your case, test for NSOrderedSame:

if (result == NSOrderedSame) {
    ...
}
Marcelo Cantos
To nitpick, `NSComparisonResult` is an `enum`, not an `int`.
Georg Fritzsche
No it isn't. The `NSOrdered...` values are members of the enum `_NSComparisonResult` (note the underscore prefix), but `NSComparisonResult` is a typedef of `NSInteger`, which is itself a typedef of `int`.
Marcelo Cantos
Apologies, i somehow overlooked that :) *(Note to self: look closely before nitpicking)*
Georg Fritzsche