How would I output this array of strings?
Say I had an array of strings...
[NSArray arrayWithObjects: @"red", @"blue", @"green", @"yellow", nil]
how would I achieve an output lik开发者_运维知识库e this...?
red is a color
blue is a color green is a color yellow is a color
Thanks!
NSArray *colors = ...;
for (NSString *color in colors) {
NSLog(@"%@ is a color", color);
}
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
精彩评论