I define a NSMutableArray *nameArray in .h file. And add strings using this nameArray in a for loop in .m file like below:
for (int i=0; i<[data count]; i++) {
NSDictionary* place = [data objectAtIndex:i];
NSString *name=[place objectForKey:@"name"];
_nameArray = [[NSMutableArray alloc] init];
[_nameArray addObject:name];
}
NSLog(@"After loop, Name is %@", _nameArray);
Actually, it should have several names in this array. But why it only output one name which was added in the array last?