2011-09-14 31 views
0

基本上,我想简单的东西像如何使Dlog日志(定制xcode NSLog)?

TimeLog {...}; 

如何使用宏,要更换的

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

occurances?

例如DLOG是

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

我有这样

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

此功能是无用的,因为我不知道调用函数的函数。我们如何决定调用函数?

我想使这个功能就像定义DLOG

可能是这样的

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

但它仍然是错误,任何一个能地狱我解决它?

所以我可以调用时间记录,如 TimeLog {DoSomething的} 并把它转换成: DLOG( “调用computeTime”); [Tools computeTime:^ {doSomething}];

宏是什么?

我该怎么做呢?

回答

1

如果你想传递参数到你的MACROS那么你应该使用另一个括号:()而不是{...}

+0

那么我该怎么做? –