美文网首页
runtime-API-property

runtime-API-property

作者: Berning | 来源:发表于2023-11-13 18:02 被阅读0次

    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);
    
    

    相关文章

      网友评论

          本文标题:runtime-API-property

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