runtime-獲取類的所有屬性

首先得導入#import <objc/runtime.h>

#pragma mark - 獲取類的所有屬性
- (NSArray *)getClassPropertrys {
    
    NSMutableArray *mutArr = [NSMutableArray array];
    
    unsigned int outCount;
    
    /** 第一個參數:要獲取哪個類的屬性
      * 第二個參數:獲取到該類的屬性的數量
     */
    objc_property_t *proList = class_copyPropertyList([UIView class], &outCount);
    
    // 遍歷所有屬性列表
    for (int i = 0; i<outCount; i++) {
        const char *name = property_getName(proList[i]);
        [mutArr addObject:[NSString stringWithUTF8String:name]];
    }
    return [NSArray arrayWithArray:mutArr];
}
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容