1 2 3 4 5 6 7 8 9 10 11 12
| NSArray *monthNames = [NSArray arrayWithObjects: @"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"December", nil]; // To mark the end of the list, nil must be specified as the last value in the list; it is not actually stored inside the array. // a easy way to set up array: @[@"January", @"February", @"March", @"April", @"May", @"June", @"July", @"August", @"September", @"October", @"November", @"December"], don't need nil. for (int i = 0; i < 12; ++i) { NSLog(@" %2i %@", i+1, [monthNames objectAtIndex:i]); // array[index] is allowed, as well as array[index] = object } // another shorter for loop for (NSString* currentString in monthNames) { NSLog(currentString); }
|