Ktmock13
Ktmock13

Reputation: 143

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 like this...?

red is a color
blue is a color
green is a color
yellow is a color

Thanks!

Upvotes: 2

Views: 2100

Answers (2)

Dave DeLong
Dave DeLong

Reputation: 243156

NSArray *colors = ...;
for (NSString *color in colors) {
  NSLog(@"%@ is a color", color);
}

Upvotes: 7

Mahesh
Mahesh

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

Related Questions