Automatic Prefixing of Classes and Methods

15 views
Skip to first unread message

Fabian Jäger

unread,
Dec 20, 2014, 4:50:32 AM12/20/14
to apple-m...@googlegroups.com
Dear Mail experts,
as I use some classes for multiple projects and I want to avoid naming conflicts, I was wondering whether there is a comfortable way of using some macro or similar to automatically add a pre- or suffix to class and method names?

Best regards,
Fabian

Scott Morrison

unread,
Dec 20, 2014, 3:15:51 PM12/20/14
to apple-m...@googlegroups.com
You can do this using macros:

If you want to use suffixes — just change the macros accordingly.

See my example — 
Create an header file for the nameSpace macros NameSpace.h

// PLUGIN_PREFIX can also defined in your preprocessor macros build settings.
#ifndef PLUGIN_PREFIX
#define PLUGIN_PREFIX MT  
#endif

#define PLUGIN_NAMESPACE_impl2(prefix, symbol) prefix ## symbol
#define PLUGIN_NAMESPACE_impl(prefix, symbol) PLUGIN_NAMESPACE_impl2(prefix, symbol)
#define PLUGIN_NAMESPACE(symbol) PLUGIN_NAMESPACE_impl(PLUGIN_PREFIX, symbol)


——

USAGE:
in your .h files for declaring classes, define the className to use the PLUGIN_NAMESPACE macro prior to class interface.
For example: MyClass.h

#import "NameSpace.h"
  
#define MyClass PLUGIN_NAMESPACE(MyClass)

// if PLUGIN_PREFIX is MT then 
// preprocessor will expand this (and every usage of MyClass) to MTMyClass
// 
@interface MyClass : NSObject

@end



Have fun not colliding your ClassNames.




--
You received this message because you are subscribed to the Google Groups "Apple Mail Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apple-mail-de...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages