I am trying to put a C-style function in the header of an Objective-C class. (My terminology might be wrong here — I’m just used to writing Objective-C class methods rather than functions). It looks as follows:
// Sort function
NSInteger sort(NSString *aString, NSString *bString, void *context);
NSInteger sort(NSString *aString, NSString *bString, void *context) {
return [aString compare:bString options:NSNumericSearch];
}
Unforuntately this results in:
Expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute‘ before ‘{‘ token
Any ideas as to what I’m missing? Thank you.
My guess is that you put the function definition within the @interface of your class. Instead, make sure C style function declarations are outside of Objective-C @interface declarations: