Challenge: instance variables (Appendix A)


#1

My solution:

[code]NSArray *BNRIvarsForClass(Class cls) {
unsigned int ivarCount = 0;

Ivar *ivarList = class_copyIvarList(cls, &ivarCount);

NSMutableArray *ivarArray = [NSMutableArray array];

for (int m = 0; m < ivarCount; m++) {
    Ivar currentIvar = ivarList[m];
    const char *ivarSelector = ivar_getName(currentIvar);
    NSString *ivarString = [NSString stringWithUTF8String:ivarSelector];
    [ivarArray addObject:ivarString];
}

return ivarArray;

}[/code]

[code]int main(int argc, const char * argv[])
{

NSArray *hierarchy = BNRHierarchyForClass(currentClass);
NSArray *methods = BNRMethodsForClass(currentClass);
NSArray *ivars = BNRIvarsForClass(currentClass);

        NSDictionary *classInfoDict = @{    @"classname"    :   className,
                                            @"hierarchy"    :   hierarchy,
                                            @"methods"      :   methods,
                                            @"ivars"        :   ivars};
        
        [runtimeClassesInfo addObject:classInfoDict];
    }
...

}
[/code]