here is the code
NSString* favPlistPath = [[NSBundle mainBundle] pathForResource:@"favs" ofType:@"plist"];
NSMutableDictionary* favPlistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:favPlistPath];
favArray = [[NSMutableArray alloc] initWithCapacity:100];
for(int i=0; i<[favPlistDict count]; i++)
{
//app is crashing here
[favArray insertObject:[favPlistDict objectForKey:[NSNumber numberWithInt:i]] atIndex:i];
}
in my favs.plist file there is single entry key: 0 value: 5
-objectForKey:returns nil if the key doesn’t exist in the dictionary. Then when you try to add the object to the array an exception is thrown because you can’t add nil to a Cocoa collection.If you want a placeholder when a value is nil, you must use
[NSNull null].The above works only in the case where the keys in favPListDict are consectuve numbers from 0 to some value.