Reputation: 143
Say I had an array of strings...
[NSArray arrayWithObjects: @"red", @"blue", @"green", @"yellow", nil]
how would I achieve an output like this...?
red is a color
blue is a color
green is a color
yellow is a color
Thanks!
Upvotes: 2
Views: 2100
Reputation: 243156
NSArray *colors = ...;
for (NSString *color in colors) {
NSLog(@"%@ is a color", color);
}
Upvotes: 7
Reputation: 34625
NSArray *initializedNSArray = [NSArray arrayWithObjects: @"red",
@"blue",
@"green",
@"yellow",
nil]
for( int i=0; i<4; ++i )
NSLog(@"%@ is a color \n", [initializedNSArray objectAtIndex: i];
// ^^^^^^^^^^^^^^^^^ to array it is earlier initialized to
Upvotes: 0