티스토리 툴바



2011/08/12 09:20

[iOS] 클래스 변수명과 그 값을 NSDictionary에 저장하기.

/***************************************************************
 스마트폰 개발에 관심이 있으시면 트윗 친구해 주세요. => @tiny2n
 ***************************************************************/


[iOS] 클래스 변수명과 그 값을 NSDictionary에 저장하기.

// --------------------------------------------------

// 변수명과 변수값을 모두 뽑아서 Dictionary 넣는다.

// --------------------------------------------------

NSMutableDictionary * dic = [[NSMutableDictionary alloc] init];

Ivar * vars = NULL;

unsigned int count = 0;


vars = class_copyIvarList([self class], &count);


for
(unsigned int i = 0; i < count; ++i) {

    NSString * key = [NSString stringWithCString:ivar_getName(vars[i]) encoding:NSUTF8StringEncoding];

    NSString * value = [self valueForKey:key];

    [dic setObject:value forKey:key];

}


free(vars);

[dic release];



Trackback 0 Comment 0