我试图动态地上课#39;属性。这是我的方法
+(NSArray *)getDictionaryKeysFromObjClass:(NSObject *)objClass{
NSMutableArray *classProperties = [[NSMutableArray alloc] init];
const char* className = class_getName([objClass class]);
id ObjectClass = objc_getClass(className);
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(ObjectClass, &outCount);
for(i=0; i<outCount; i++){
objc_property_t *property = properties[i];
//[classProperties addObject:property];
NSLog(@"Property > %@", property);
}
}
所以我不确定我是否正确地做到了,就像我这样称呼它一样:
NSMutableArray *testarr = [WCFServiceRequest getDictionaryKeysFromClass:[MyFirstClass class]];
会引发错误:
NSInvalidArgumentException&#39;,原因:&#39; + [WCFServiceRequest getDictionaryKeysFromClass:]:发送到类
的无法识别的选择器
对我做错了什么的想法?
感谢!!!
答案 0 :(得分:2)
你做错了
NSMutableArray *testarr = [WCFServiceRequest getDictionaryKeysFromClass:[MyFirstClass class]];
------------------------------------------------------------------^Obj is missing
应该是:
NSMutableArray *testarr = [WCFServiceRequest getDictionaryKeysFromObjClass:[MyFirstClass class]];
由于您的方法是:
+(NSArray *)getDictionaryKeysFromObjClass:(NSObject *)objClass;