zoukankan      html  css  js  c++  java
  • 使用runtime获取属性

    在   YuansPerson 类中定义属性(在.h 和.m 中定义都可以)

    class_copyIvarList:获取类的所有属性变量,count记录变量的数量IVar是runtime声明的一个宏,是实例变量的意思,instance variable,在runtime中定义为 typedef struct objc_ivar *Ivari

    var_getName:将IVar变量转化为字符串

    ivar_getTypeEncoding:获取IVar的类型

     

     object_setIvar(<#id obj#>, <#Ivar ivar#>, <#id value#>)  :  可以强制修改原属性的值

     

     

     YuansPerson *yuansPerson = [YuansPerson new];

     

     unsigned int count = 0;

     Ivar *nameList = class_copyIvarList([YuansPerson class], &count);

        

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

            

            Ivar var = nameList[i];

            const char *name = ivar_getName(var) ;

            const char *type = ivar_getTypeEncoding(var);

            

            NSLog(@"name = %s type = %s",name,type);

        

             

        }

        

     

     

     

     

    我是一只小鸟,但我也要飞向更高的蓝天,总有一天会长大的。
  • 相关阅读:
    更改ubuntu的官方镜像源
    python中的decorator的作用
    thunderbird 设置 邮件回复时内容在上方显示
    Sapnco3 RfcTable Structure
    DbEntry 访问Access2010数据库
    DbEntry 默认 主键ID为long
    DbEntry 简单实现
    nginx学习时使用EditPuls编辑conf.xml
    java的集合类面试题
    tomcat组成介绍和调优方案
  • 原文地址:https://www.cnblogs.com/Stone-Yuan/p/6282153.html
Copyright © 2011-2022 走看看