开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜