Tutorial :NSUnknownKeyException, KVC compliance code not working


the following piece of code which gets successfully built and also seems alright to me but doesn't work... mind that i am new to key value coding and your help will be greatly appreciated... in table view delegate didSelectRowAtIndexPath: method here the categoriesList is a simple table with 5 entries

NSUInteger row = [indexPath row];  NSString *rowString = [categoriesList objectAtIndex:row];  NSString *path = [[NSBundle mainBundle] pathForResource:@"DataBase" ofType:@"plist"];  NSDictionary *rootDict = [[NSDictionary alloc] initWithContentsOfFile:path];  NSArray *allRootKeys = [rootDict allKeys];  NSMutableArray *mutableArray = [[NSMutableArray alloc] init];  for (NSString *name in allRootKeys) {      NSInteger index = [allRootKeys indexOfObject:name];      NSDictionary *newDict = [allRootKeys objectAtIndex:index];      if ([newDict valueForKey:@"Class"] == rowString)          [mutableArray addObject:[allRootKeys objectAtIndex:index]];   }     NSArray *childControllerArray = [[NSArray alloc] initWithArray:mutableArray];  

now i pass childControllerArray to the loadArray ivar of my next controller which gets pushed when any row is selected with the specific array and it displays the contents of that array.... when i delete the above code and pass a simple array of objects to it , It WORKS just fine.... PLEASE HELP

the exception given is:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCFString 0x543eb0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Class.


[rootDict allKeys]; //this is an array of NSStrings, NOT Array of NSDictionarys

This code can't work

NSArray *allRootKeys = [rootDict allKeys];  NSDictionary *newDict = [allRootKeys objectAtIndex:index];   

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »