0
我想動態獲取一個類的屬性。這是我的方法目標c動態獲取一個nsobjects屬性
+(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);
}
}
所以我不知道如果我做正確的whenver我這樣稱呼它:
NSMutableArray *testarr = [WCFServiceRequest getDictionaryKeysFromClass:[MyFirstClass class]];
這將引發錯誤:
NSInvalidArgumentException', reason: '+[WCFServiceRequest getDictionaryKeysFromClass:]: unrecognized selector sent to class
關於我在做什麼的錯誤?
謝謝!
我堅持你[參考這篇文章(HTTP:/ /stackoverflow.com/questions/848636/objective-c-2-0-class-copypropertylist-how-to-list-properties-from-categorie) –