I don't see you pointing the names pointer at an NSMutableArray - you declared the pointer variable but never created an object for it to point to
Code:
NSMutableArray *names;
NSArray *keys;
int i, count;
id key, value;
names = [NSMutableArray array]; //setting names here
keys = [dictionary allKeys];
count = [keys count];
for (i = 0; i < count; i++)
{
key = [keys objectAtIndex: i];
value = [dictionary objectForKey: key];
NSLog (@"value:%@", value);
NSString *pName = [value objectForKey:@"personName"];
NSLog (@"pName:%@", pName);// the debugger shows the correct pName string with each loop
[names addObject:pName];
}
NSLog (@"names:%@", names);
Now it should work, but I'll go you two better. First with some fast enumeration:
Code:
NSMutableArray *names = [NSMutableArray array];
NSArray *values = [dictionary allValues];
for (id value in values)
{
NSString *pName = [value objectForKey:@"personName"];
[names addObject:pName];
}
NSLog (@"names:%@", names);
Or better yet, some key-value coding:
Code:
NSArray *values = [dictionary allValues];
NSArray *names = [values valueForKey:@"personName"];
NSLog (@"names:%@", names);
Names is not mutable in the last example, but you could call mutableCopy on it if you need to.
-- Society for the Elimination of most Loops