我们可以将变量打印成宏吗?

时间:2012-05-21 09:50:49

标签: objective-c xcode4.3

我经常这么做

    CLog(@"someNew.Title %@", someNew.Title); //Working
    CLog (@"_currentBusiness.managedObjectContext %@",_currentBusiness.managedObjectContext);
    CLog (@"someNew.managedObjectContext %@",someNew.managedObjectContext);
    CLog (@"[ThreadClass managedObjectContext] %@",[ThreadClass managedObjectContext]);
    CLog (@"UIAppDelegate.managedObjectContext %@",UIAppDelegate.managedObjectContext);

基本上我做

CLog (@"VariableName %@", VariableName)

有没有办法把它变成一个宏?

1 个答案:

答案 0 :(得分:3)

这应该有效 - 像这样定义宏:

#define CLOG(x) CLog(@#x " %@", x)

然后像这样调用它:

CLOG(someNew.Title);