iOS runtime 가져오기 방법 목록 및 구성원 변수

1913 단어 iOS

#import "NSObject+runtime.h"
#import 

@implementation NSObject (runtime)
/*   */
+(NSArray *)getAllProperties {
    u_int count;
    objc_property_t *properties  =class_copyPropertyList([self class], &count);
    NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];
    
    for (int i = 0; i < count ; i++)
    {
        const char* propertyName =property_getName(properties[i]);
        [propertiesArray addObject: [NSString stringWithUTF8String: propertyName]];
    }
    free(properties);
    
    NSLog(@"====> %@ : %@", NSStringFromClass([self class]), propertiesArray.description);
    return propertiesArray;
}



/*   */
+(NSArray *)getAllMethods {
    unsigned int methodCount =0;
    Method* methodList = class_copyMethodList([self class],&methodCount);
    NSMutableArray *methodsArray = [NSMutableArray arrayWithCapacity:methodCount];
    
    for(int i=0;i %@ : %@", NSStringFromClass([self class]), methodsArray.description);
    return methodsArray;
}


/*   */
+ (NSDictionary *)getAllPropertiesAndVaules:(NSObject *)obj {
    NSMutableDictionary *propsDic = [NSMutableDictionary dictionary];
    unsigned int outCount;
    objc_property_t *properties =class_copyPropertyList([obj class], &outCount);
    for ( int i = 0; i %@ : %@", NSStringFromClass([self class]), propsDic.description);
    return propsDic;
}

@end

좋은 웹페이지 즐겨찾기