Anyway to get string from variable name?

后端 未结 5 1417
不思量自难忘°
不思量自难忘° 2020-11-29 07:48

Say I have my class

@interface Person : NSObject { NSString *name; }

I need to get the name of NSString\'s within my class



        
5条回答
  •  星月不相逢
    2020-11-29 08:10

    As easy as

    #define VariableName(arg) (@""#arg)

    Then you do:

    NSObject *obj;
    NSString *str = VariableName(obj);
    NSLog(@"STR %@", str);//obj
    

提交回复
热议问题