iOS Build a Simple iPhone App with Objective-C Creating a Data Model Creating a Data Collection

Stefan Mach
Stefan Mach
3,691 Points

Now stuck on number 3

Just can't get the syntax.

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@property (nonatomic, strong) NSArray *shoppingList;

@end
ViewController.m
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!

  self.shoppingList = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];

  self.shoppingCart = [[NSString alloc] initWithObjectAtIndex : 2];
}

@end

1 Answer

Aniruddha Shukla
Aniruddha Shukla
2,846 Points

You need to retrieve the object at Index 2 from the shoppingList Array.

// Add your code below!
self.shoppingList = @[@"toothpaste", @"bread", @"eggs"];  
self.shoppingCart = [self.shoppingList objectAtIndex:2];