user4951
user4951

Reputation: 33130

how to make timeLog like Dlog (customize xcode NSLog)?

Basically I want to replace occurances of

Dlog ("Calling computeTime");
[Tools computeTime:^{...}];

with something simpler like

TimeLog {...};

How can I use macro for that?

example DLog is

#ifdef DEBUG
#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... ) 
#endif

I have a function like this

+(void) computeTime:(void (^)())block
{
    NSDate * currentTime = [NSDate date];
    block();
    DLog(@"Time Running is: %f", [[NSDate date] timeIntervalSinceDate:currentTime]);
}

This function is useless because I do not know the calling function. How do we decide calling function?

I want to make this function like define Dlog

may be like that

#ifdef DEBUG
#define TimeLog {...} [Tools computeTime:^{...}];
#else
#define TimeLog {...} 
#endif

but it's still error, any one can hell me to fix it?

So I can call that time log such as TimeLog {doSomething} and turn that into: Dlog ("Calling computeTime"); [Tools computeTime:^{doSomething}];

what would the macro be?

how can I do it well?

Upvotes: 0

Views: 377

Answers (1)

Nekto
Nekto

Reputation: 17877

If you want to pass parameters to your MACROS then you should use another brackets: () not {...}.

Upvotes: 1

Related Questions