//
//  Peoples.m
//  objc-test
//
//  Created by huangyirong on 2020/4/3.
//

#import "Peoples.h"
#import <objc/message.h>

@implementation Peoples


-(instancetype)init{
    self = [super init];
    if (self) {
        [self modifyProperty];
    }
    return self;
}
//2、获取类的属性列表-并修改属性值
-(void)modifyProperty{
    NSLog(@"kkkk");
    unsigned int count = 0;
    Ivar *ivarList = class_copyIvarList(self.class, &count);
    for (NSUInteger i=0; i<count; i++) {
        Ivar ivar = ivarList[i];
        const char *ivarAddresss = ivar_getName(ivar);
        const char *ivarType = ivar_getTypeEncoding(ivar);
        NSString *address = [NSString stringWithUTF8String:ivarAddresss];
        NSLog(@"%d :ivarAddresss:%s  ivarType:%s",i,ivarAddresss,ivarType);
        //修改属性值
        if ([address isEqualToString:@"_ivar_name"]) {
            object_setIvar(self, ivar, @"123456");
        }
    }
    //    NSLog(@"_ivar_name:%@",_ivar_name);
}


@end
