首先得導入#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];
}