I made this method
-(NSMutableArray *)getProperties:(id)c
{
NSString *propertyName;
unsigned int outCount, i;
NSMutableArray *propertieNames = [[NSMutableArray alloc] initWithObjects: nil];
objc_property_t *properties = class_copyPropertyList(c, &outCount);
for (i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
propertyName = [NSString stringWithUTF8String:property_getName(property)];
[propertieNames addObject:propertyName];
}
return propertieNames;
}
I use this
NSMutableArray *propertiesNames = [self getProperties:[self class]];
I want to use this
NSMutableArray *propertiesNames = [[self class] getProperties];
How to add category to Class class. maybe Class class is not Object….
I try add category to Class
#import "Class+SN.h"
@implementation Class (SN)
@end
I got error
Cannot find interface declaration for 'Class'
If you want a class method, you have to use
+instead of-. In class methods,selfrefers to the class, so you can replacecwithself. The documentation forclass_copyPropertyListsays that you need to free the list later withfree(), otherwise you are leaking memory.Also, Objective-C method names rarely use
get. Many methods withgetin the name imply that they have output parameters or that the caller should provide their own buffer (for examples of when to usegetin the name, seegetCharacters:range:, and alsogetStreamsToHost:port:inputStream:outputStream:). This convention means your method would be more appropriately namedpropertiesorclassPropertiesetc.