user4951
user4951

Reputation: 33130

Can we turn printing a variable into a macro

I often do this a lot

    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);

Basically I do

CLog (@"VariableName %@", VariableName)

Is there a way to turn this into a macro?

Upvotes: 1

Views: 71

Answers (1)

Paul R
Paul R

Reputation: 213080

This should work - define the macro like this:

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

and then invoke it like this:

CLOG(someNew.Title);

Upvotes: 3

Related Questions