tags:

views:

1903

answers:

1

Hi all,

In my objective c class, I'd like to sort an array like this:

NSArray *sorted = [unsortedArray sortUsingFunction: mySort context: NULL];

My sort function is implemented as:

NSInteger mySort(id one, id two, void *ctx) { return 1; }

When I build the program the compiler tells me:

error: void value not ignored as it ought to be

Now I think I know what the compiler is trying to tell me:

"I don't know what the heck "mySort" is so I will assume it returns 'void'. Oops, looks like you are trying to assign 'void' to a variable, nope can't do that. Try again."

Alright, Mr. compiler, what in the world to I have to tell you so you know the function prototype is NSInteger mySort(id, id, void*)? I tried putting that line in the class header file, before the "@interface", after, pretty much all over the place, but I can't get this to work.

Where/how do I have to declare the function prototype for my sort function?

Big thanks in advance, Mark.

+3  A: 

sortUsingFunction: is an NSMutableArray method that re-orders the array object and does not return a value. It looks like you're looking for sortedArrayUsingFunction:, an NSArray method that returns a sorted, autoreleased shallow copy of the array.

Marc Charbonneau