-2

I'm trying to create a compare function like the example on the apple site:

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray%5FClass/NSArray.html#//apple%5Fref/occ/instm/NSArray/sortedArrayUsingFunction%3Acontext%3A

The example is not objective-c. Does anyone know how I can convert the example:

NSInteger intSort(id num1, id num2, void *context)
{
int v1 = [num1 intValue];
int v2 = [num2 intValue];
if (v1 < v2)
    return NSOrderedAscending;
else if (v1 > v2)
    return NSOrderedDescending;
else
    return NSOrderedSame;
}

to a function I can call with sortedArrayUsingFunction.

Thanks!

Atma
  • 29,141
  • 56
  • 198
  • 299
  • 2
    This example is most definitely Objective-C (it uses Objective-C message passing in the first two lines, as well as the id type in the calling isgnature). And it works for the use you're after. – Barry Wark Sep 14 '09 at 19:53

1 Answers1

2

That function works with sortedArrayUsingFunction, see my updated answer on your other question for how to call it

Community
  • 1
  • 1
slf
  • 22,595
  • 11
  • 77
  • 101