views:

94

answers:

4

I'm taking a tutorial for X-code that says this:

"Go into the code and change the references from DrinkArray to DrinksDirections."

What exactly does it mean?

I would show you the tutorial, except it's a book that costs money.

The only reference I found of DrinkArray is:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkArray" ofType:@"plist"];
    NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
    self.drinks = tmpArray;
    [tmpArray release];
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
A: 

The type of some declared reference variable is DrinkArray. It's telling you to change the type to DrinksDirection. Can you paste the code snippet?

Amir Afghani
the whole thing or just little parts?
Nathan
How big is the whole thing? Post like 10-15 relavent lines.
Amir Afghani
+1  A: 

"Reference" is not a precise technical term in Objective-C, so what it means is whatever the author meant was thinking of when he wrote it. The term is sometimes used in "passed by reference" or "returned by reference," in which case "reference" means "pointer" — but that doesn't seem to be the usage here. Most likely the tutorial means to change places where your code mentions "DrinkArray" to instead say "DrinksDirections."

Chuck
Yeah, and it says it's supposed to crash after it, but it just does the same thing...
Nathan
+1  A: 

This is from Head First iPhone Development. The code in viewDidLoad that you found is where you want to make the change:

NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkArray" 
                                        ofType:@"plist"];

This line basically asks for the file path to the DrinkArray.plist bundled with the application. In the tutorial the next step is to migrate to a dictionary based array where each element contains a name, ingredients and directions.

Rather than typing out each entry by hand, they've provided a copy of the updated plist named DrinkDirections.plist in the book downloads. After downloading the sample files, copy the DrinkDirections.plist into your project Resources folder. Then change the line in viewDidLoad to

NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkDirections" 
                                        ofType:@"plist"];

This asks for the path to the DrinkDirections.plist that you've just added to your project. Be aware that your application will crash after making this change - that's OK, it's part of the tutorial and is covered in the immediately following pages.

Paul Alexander
A: 

okay, I figured it out. It wasn't DrinkDirections, it was DrinksDirections. It's stupid that a little thing can mess up a whole program.

Nathan