Reputation: 4825
I have long liked to visually segment Protocol implementation code using the following:
// UIApplicationDelegate ===========================================================================
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)options {
However, the #pragma mark feature in Xcode is really quite useful. I also like the ability to add dividing lines. But this means my code now looks like:
// UIApplicationDelegate ===========================================================================
#pragma mark -
#pragma mark UIApplicationDelegate
- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)options {
Which is becoming quite unwieldy. I really like the nice (normally) green line marked with the protocol embedded into the code itself, but I also like the pragma mark utility.
Is there anyway using preprocessor #define
or other such commands to automatically convert the first into the 2nd?
Upvotes: 2
Views: 232
Reputation: 126137
Clang / Xcode also recognizes // MARK:
for the same purpose as #pragma mark
. (Also, this is the only style in Swift, since that language doesn't have a preprocessor.) So if you like green, you could do:
// MARK: - UIApplicationDelegate
// ========================
If you're looking for a way to automatically convert all uses of your previous notation to // MARK
or #pragma
, I'd recommend a good regex find/replace utility, of which there are too many to list here.
Upvotes: 3
Reputation: 137850
You can generate a #pragma
from a macro, but the text editor won't see it unless it does macro expansion.
The _Pragma
"operator" is defined to have the same effect as a #pragma
directive.
#define PRAGMA_STR( TEXT ) _Pragma( # TEXT )
#define INDEX_MARK( NAME ) _Pragma("mark -") PRAGMA_STR(mark NAME)
It won't work within a comment, but you could do something like
INDEX_MARK( UIApplicationDelegate ) // =======================================
… if the editor looked at macros, which it probably doesn't.
Upvotes: 1