NSMutableArray *nameArray = [[NSMutableArray alloc] init];
[nameArray addObject:@"abc"];
[nameArray addObject:@"cdf"];
[nameArray addObject:@"jkl"];
//Use a for each loop to iterate through the array
for (NSString *s in nameArray) {
NSLog(@"value is %@", s);
}
The above code shows all the values of nameArray. But I want to assign all those values to these NSString:
NSString *a;
NSString *b;
NSString *cd;
An aray can have 1 or more elements but not more than 5.
Actually,I have 5 buttons, each button on click will add a NSString value(values are: f1,f2,f3,f4 and f5) to NSMutableArray. Now its upto the user if he clicks 2 buttons or 3 or 5 in a day. Now all these values will be saved in NSMutableArray (which can be 1 or 2 but not more than 5). That NSMutableArray will be saved in NSUserDefaults. This NSMutableArray than will be used in another view where I have some UIImageView (1,2,3,4 and 5). Now when I will get the string values from that Array(f1,f2,f3). If it is f1 then an image will be assigned to UIImage 1 if it is f3 then to image 3 and so on.
How to achieve this?
myLabel.text = [nameArray objectAtIndex:0];- by assigning them to other pointers you're running the risk of bad memory management :(