美文网首页
runtime-API-ivar

runtime-API-ivar

作者: Berning | 来源:发表于2023-09-19 07:11 被阅读0次

    1.获取成员变量/名称/类型/偏移量

    • class_getInstanceVariable
    • ivar_getName
    • ivar_getTypeEncoding
    • ivar_getOffset
        Ivar age_ivar = class_getInstanceVariable(NSPerson.class, "_age");
        const char *age_name = ivar_getName(age_ivar);
        const char *age_type = ivar_getTypeEncoding(age_ivar);
        
        /**
        @note For instance variables of type \c id or other object types, call \c object_getIvar
         and \c object_setIvar instead of using this offset to access the instance variable data directly.
        */
        ptrdiff_t age_offset = ivar_getOffset(age_ivar);
        NSLog(@"age_name:%s",age_name);
        NSLog(@"age_type:%s",age_type);
        NSLog(@"%td",age_offset);
        
        
         
    }
    
    

    相关文章

      网友评论

          本文标题:runtime-API-ivar

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