4

How to add a prefix to a method with C macro? For example:

#define CategoryName aNewCategory
#define Concatenate(prefix, methodName) prefix##_##methodName
#define AddCategoryPrefix(methodName) Concatenate(CategoryName, methodName)

@implementation NSObject(CategoryName)
+ (void) AddCategoryPrefix(logTask){
}
@end

The method name will be CategoryName_logTask, not aNewCategory_logTask as I want.

Xaree Lee
  • 3,188
  • 3
  • 34
  • 55
  • 4
    Duplicate: http://stackoverflow.com/questions/1489932/c-preprocessor-and-concatenation – Henrik Oct 10 '13 at 12:11
  • Thank you for your link! It helps a lot. – Xaree Lee Oct 10 '13 at 13:13
  • Possible duplicate of [How to concatenate twice with the C preprocessor and expand a macro as in "arg ## \_ ## MACRO"?](https://stackoverflow.com/questions/1489932/how-to-concatenate-twice-with-the-c-preprocessor-and-expand-a-macro-as-in-arg) – Mathieu Jan 10 '19 at 15:55

0 Answers0