Challenge: a grocery list

File: main.m

Using old-style array methods (arrayWithObjects:)

[code]#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

@autoreleasepool {
    
    // Chapter 17 NSArray
    // Challenge: a grocery list
    NSMutableArray *groceryList = [NSMutableArray arrayWithObjects:@"Loaf of bread",@"Container of milk", @"Stick of butter", nil];
    
    NSLog(@"My grocery list is:\n");
    for (NSString *item in groceryList) {
        NSLog(@"%@\n", item);
    }
    
}
return 0;

}
[/code]

Output:
2014-08-20 11:26:11.825 Groceries[680:303] My grocery list is:
2014-08-20 11:26:11.826 Groceries[680:303] Loaf of bread
2014-08-20 11:26:11.827 Groceries[680:303] Container of milk
2014-08-20 11:26:11.827 Groceries[680:303] Stick of butter
Program ended with exit code: 0

I like that you used β€˜item’ for your variable name. I had just stuck in β€˜d’ again. Item much better.

1 Like