是否可以在 Objective-c 中执行以下操作?
NSString *propertyName = NSStringFromSelector(aPerson.personName);
propertyName
会有字符串personName
;
我想把它归为NSObject
.
是否可以在 Objective-c 中执行以下操作?
NSString *propertyName = NSStringFromSelector(aPerson.personName);
propertyName
会有字符串personName
;
我想把它归为NSObject
.
获取一个类的所有属性名
- (NSMutableArray *)getAllPropertyOfClass:(Class)aClass {
NSMutableArray *mArray=[NSMutableArray new];
unsigned int outCount;
objc_property_t *properties = class_copyPropertyList([aClass class], &outCount);
for(unsigned int i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
const char *propName = property_getName(property);
if(propName) {
NSString *propertyName = [NSString stringWithUTF8String:propName];
mArray[mArray.count]=propertyName;
}
}
free(properties);
return mArray;
}