Anyway to get string from variable name?

后端 未结 5 1413
不思量自难忘°
不思量自难忘° 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:20

    You can get the names of a class's instance variables with the Objective-C runtime API function class_copyIvarList. However, this is rather involved, rarely done and almost never the best way to accomplish something. If you have a more specific goal in mind than mere curiosity, it might be a good idea to ask about how to accomplish it in Objective-C.

    Also, incidentally, person.name doesn't specify an instance variable in Objective-C — it's a property call. The instance variable would be person->name.

提交回复
热议问题