Class_copyPropertyList: Gets the class property variables by the class name.
Class_copyIvarList: Gets the instance variables of a class by its name.
In other words:
Class_copyPropertyList gets variables that are modified by @Property,
Class_copyIvarList gets the variables that class_copyPropertyList modifies and that are defined inside the @implementation inside the M file
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface Model : NSObject
@property (nonatomic,copy) NSString *sex;
@property (nonatomic,copy) NSString *name;
@property (nonatomic,assign) NSInteger age;
@property (nonatomic,strong) NSDictionary *imgCode;
@end
NS_ASSUME_NONNULL_END
Copy the code
#import "Model.h"
@interface Model()
@property (nonatomic,copy) NSString *Id;
@end
@implementation Model
{
NSInteger _index;
}
@end
Copy the code
#import "LGTestViewController.h" #import "Model.h" @interface LGTestViewController () @end @implementation LGTestViewController - (void)viewDidLoad { [super viewDidLoad]; // Unsigned int propertiesCount = 0; unsigned int ivarsCount = 0; objc_property_t *properties = class_copyPropertyList([Model class], &propertiesCount); Ivar *ivars = class_copyIvarList([Model class], &ivarsCount); NSLog(@"propertiesCount = %u,ivarsCount = %u",propertiesCount,ivarsCount); //propertiesCount = 5,ivarsCount = 6 }Copy the code