如何使timeLog像Dlog一样(自定义xcode NSLog)?
基本上我想
Dlog ("Calling computeTime");
[Tools computeTime:^{...}];
用更简单的东西替换出现的东西,例如
TimeLog {...};
如何使用宏来实现这一点?
例如 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]);
}
这个函数没有用,因为我不知道调用函数。我们如何决定调用函数?
我想让这个函数像define Dlog
一样
#ifdef DEBUG
#define TimeLog {...} [Tools computeTime:^{...}];
#else
#define TimeLog {...}
#endif
,但它仍然是错误的,任何人都可以让我修复它吗?
所以我可以称该时间日志为 时间日志{doSomething} 并将其变成: Dlog("调用computeTime"); [工具computeTime:^{doSomething}];
宏会是什么?
我怎样才能做好呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将参数传递给
MACROS
,那么您应该使用另一个括号:()
而不是{...}
。If you want to pass parameters to your
MACROS
then you should use another brackets:()
not{...}
.