runtime 클래스 속성 목록과 방법 목록 가져오기

2052 단어

객체의 모든 속성 가져오기

/*   */
+(NSArray *)getAllProperties
{
    u_int count;
    //  count  &count
    objc_property_t *properties  =class_copyPropertyList([self class], &count);
    //arrayWithCapacity 
    NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];

    for (int i = 0; i < count ; i++)
    {
        // propertyName c 
        const char* propertyName =property_getName(properties[i]);
        // c OC NSString
        [propertiesArray addObject: [NSString stringWithUTF8String: propertyName]];
    }
    //class_copyPropertyList C , properties
    // You must free the array with free().
    free(properties);

    return propertiesArray;
}  ```
####  

/* 객체를 가져오는 모든 방법*/+(NSArray) getAllMethods {unsigned int methodCount = 0, Method methodList = class copy MethodList([self class], & methodCount), NSMutable Array *methodsarray = [NSMutable Array array Wity:methodCount];
for(int i=0;i

} ```

객체의 모든 속성 및 속성 컨텐트 가져오기

/*   */
+ (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

import ```

좋은 웹페이지 즐겨찾기