How do I list all fields of an object in Objective-C?

后端 未结 3 2002
说谎
说谎 2020-12-03 02:47

If I have a class, how can I list all its instance variable names?

eg:

@interface MyClass : NSObject {
    int myInt;
    NSString* myString;
    NSM         


        
3条回答
  •  萌比男神i
    2020-12-03 03:53

    #import 
    
    
    NSUInteger count;
    Ivar *vars = class_copyIvarList([self class], &count);
    for (NSUInteger i=0; i

提交回复
热议问题