YYClassIvarInfo.h.m

作者: Laughingg | 来源:发表于2016-07-28 16:58 被阅读12次
    /**
     Instance variable information.
     */
    @interface YYClassIvarInfo : NSObject
    @property (nonatomic, assign, readonly) Ivar ivar;              ///< ivar opaque struct
    @property (nonatomic, strong, readonly) NSString *name;         ///< Ivar's name
    @property (nonatomic, assign, readonly) ptrdiff_t offset;       ///< Ivar's offset
    @property (nonatomic, strong, readonly) NSString *typeEncoding; ///< Ivar's type encoding
    @property (nonatomic, assign, readonly) YYEncodingType type;    ///< Ivar's type
    
    /**
     Creates and returns an ivar info object.
     
     @param ivar ivar opaque struct
     @return A new object, or nil if an error occurs.
     */
    - (instancetype)initWithIvar:(Ivar)ivar;
    @end
    
    @implementation YYClassIvarInfo
    
    - (instancetype)initWithIvar:(Ivar)ivar {
        if (!ivar) return nil;
        self = [super init];
        _ivar = ivar;
        const char *name = ivar_getName(ivar);
        if (name) {
            _name = [NSString stringWithUTF8String:name];
        }
        _offset = ivar_getOffset(ivar);
        const char *typeEncoding = ivar_getTypeEncoding(ivar);
        if (typeEncoding) {
            _typeEncoding = [NSString stringWithUTF8String:typeEncoding];
            _type = YYEncodingGetType(typeEncoding);
        }
        return self;
    }
    
    @end
    

    相关文章

      网友评论

        本文标题:YYClassIvarInfo.h.m

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