Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJustin Whedon
19,811 PointsHaving issues with task 3 of 3 on the shoppingCart challenge.
What am I doing wrong here? Trying to add 'eggs' to the 'shoppingCart'.
import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad]; self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste",@"bread", @"eggs",nil]; NSString *shoppingCart = [shoppingList objectAtIndex:2]; }
@end
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@property (nonatomic, strong) NSArray *shoppingList;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste",@"bread", @"eggs",nil];
NSString *shoppingCart = [shoppingList objectAtIndex:2];
}
@end
1 Answer
Rashii Henry
16,433 PointsHey Justin,
once you declare a property in a viewController. It becomes accessible all throughout that class. You did that in your header file flawlessly, with shoppingCart.
However, in your implementation, you created a new instance of shoppingCart, sorta like you didn't want to use what you had already created.
Now the compiler is assigning it to a different location. So try using the syntax you have with your shoppingList. You should be good to go.
Justin Whedon
19,811 PointsJustin Whedon
19,811 PointsThanks so much.