NSLog - How to print object name?

前端 未结 1 875
春和景丽
春和景丽 2021-01-19 23:49

Consider,

NSString *myString = @\"Welcome\";

NSLog(@\"%@\",myString);

will print Welcome in console.

Can I print the

相关标签:
1条回答
  • 2021-01-20 00:21

    Use the following code:

    #define stringVariable(x) NSLog( @"%s:%@",#x, x) 
    
    NSString *myString=@"Welcome";
    
    stringVariable(myString); 
    

    Note: The general principle is that when you put a # in front of an argument within the body of a #define, the preprocessor replaces it with a C string of the exact expression passed to the macro. When you pass a variable name, you'll get that name.

    0 讨论(0)
提交回复
热议问题