Test code for arrays in Objective-C
double income1;
double income2;
double income3;
income1 = 150000.00;
income2 = 2103456.78;
income3 = 555555.55;
income1 = income1 + income1*0.10;
income2 = income2 + income2*0.10;
income3 = income3 + income3*0.10;
NSLog(@"income1: %6.2f", income1);
NSLog(@"income2: %6.2f", income1);
NSLog(@"income3: %6.2f", income1);
double income[3]; // array of doubles
income[0] = 150000.00;
income[1] = 2120456.78;
income[2] = 555555.55;
for(int i = 0; i <3; i++)
income[i] = income[i] + income[i]*0.10;
for(int i = 0; i <3; i++)
NSLog(@"income %2d: %6.2f", i, income[i]);
NSString *words[5]; // C-style array of NSStrings
words[0] = @"this";
words[1] = @"class";
words[2] = @"is";
words[3] = @"so";
words[4] = @"easy";
for( int i = 0; i < 5; i++ )
NSLog(@"%@", words[i]);
// NSArray of NSStrings
NSArray *temp = [NSArray arrayWithObjects:@"one",@"two",@"three",nil];
for( int i = 0; i < temp.count; i++ )
NSLog(@"%@", temp[i]);
for( int i = 0; i < temp.count; i++ )
NSLog(@"%@", [temp objectAtIndex:i]);
// NSMutableArray of NSStrings
NSMutableArray *strings = [[NSMutableArray alloc] init];
[strings addObject:@"hey"];
[strings addObject:@"there"];
for( int i = 0; i < strings.count; i++ )
NSLog(@"%@", strings[i]);
[strings addObject:@"hello"];
for( int i = 0; i < strings.count; i++ )
NSLog(@"%@", [strings objectAtIndex:i]);