runtime-API-property

1.获取属性名

    objc_property_t name_property = class_getProperty(NSPerson.class, "name");
    const char * property_name = property_getName(name_property);
    NSLog(@"name_property:%s",property_name);

2.获取属性信息

    const char * property_attributes = property_getAttributes(name_property);
    NSLog(@"property_attributes:%s",property_attributes);

3.拷贝属性信息

    unsigned int attributes_count;
    objc_property_attribute_t *attributes_list = property_copyAttributeList(name_property, &attributes_count);
    for (int i = 0; i < attributes_count; i++) {
        objc_property_attribute_t attribute = *(attributes_list + i);
        NSLog(@"name_%i:%s,value_%i:%s",i,attribute.name,i,attribute.value);
    }
    free(attributes_list);

4.拷贝指定属性信息的值

    char * property_value = property_copyAttributeValue(name_property, "V");
    NSLog(@"property_value:%s",property_value);
    free(property_value);

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、 1.动态创建一个类(参数:父类、类名、额外的内存空间)objc_allocateClassPair(Clas...
    xlii阅读 353评论 0 1
  • 目录 一、属性声明的概念、构成、访问 二、属性声明的自动合成 三、属性声明的可选选项 ( 关键字 ) 四、属性的 ...
    半纸渊阅读 7,665评论 5 19
  • runtime的所有知识基本都围绕两个中心(1)类的各个方面的动态配置(2)消息传递 要动态配置类就需要知道类的本...
    东丶小菜鸟阅读 954评论 1 3
  • 1.获取协议 2.拷贝协议列表 3.判断协议是否遵守了另一个协议 4.判断两个协议是否为同一个协议 5.获取协议名...
    Berning阅读 128评论 0 0
  • 前言:本文只是分类列举一些常用Runtime API👉一些Runtime 常用场景 1. 类 动态创建一个类 注册...
    Gxdy阅读 580评论 0 0