美文网首页
runtime获取属性,成员变量

runtime获取属性,成员变量

作者: Vergil_wj | 来源:发表于2017-02-25 14:04 被阅读12次

    unsigned int count = 0;

    objc_property_t *propertys = class_copyPropertyList([UIDatePicker class], &count);

    for(int i = 0;i < count;i ++){

    //获得每一个属性

    objc_property_t property = propertys[i];

    //获得属性对应的nsstring

    NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];

    //输出打印看对应的属性

    NSLog(@"《》《》《》《》《》《》《》propertyname = %@",propertyName);

    }

    ————————————————————————————

    Ivar *ivars = class_copyIvarList([UIDatePicker class], &count);

    for(int i =0;i < count;i ++){

    Ivar ivar = ivars[i];

    NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];

    NSLog(@"<><><><><><><><><><><>.ivarName = %@",ivarName);

    }

    相关文章

      网友评论

          本文标题:runtime获取属性,成员变量

          本文链接:https://www.haomeiwen.com/subject/npzgwttx.html