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 trialBrendan Corey
Courses Plus Student 5,745 PointsNot understanding what I am doing wrong with question 3 of 3 in 'Creating a Data Collection'
shoppingCart = [shoppingList objectAtIndex:2];
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@property (strong, nonatomic) NSArray *shoppingList;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
self.shoppingList = @[@"toothpaste", @"bread", @"eggs"];
shoppingCart = [shoppingList objectAtIndex: 2];
}
@end
1 Answer
Holger Liesegang
50,595 PointsHi Brendan Corey !
You solved Challenge Task 3 of 3 "We're at the grocery store shopping and we found the eggs. In the header file we have a property, shoppingCart, of type NSString. In the viewDidLoad method, retrieve the string eggs from the shoppingList array and store it in shoppingCart. Hint: use the 'objectAtIndex' method." nearly complete. You only forgot to use "self" while referencing the properties of the class: self.shoppingCart = [self.shoppingList objectAtIndex: 2];
#import "ViewController.h"
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@property (strong, nonatomic) NSArray *shoppingList;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add your code below!
self.shoppingList = @[@"toothpaste", @"bread", @"eggs"];
self.shoppingCart = [self.shoppingList objectAtIndex: 2];
}
@end
Brendan Corey
Courses Plus Student 5,745 PointsBrendan Corey
Courses Plus Student 5,745 PointsAppreciate the assistance. Tried everything. was unaware about using the self.shoppingList objectAtIndex: 2 dot notation within the parentheses.
Holger Liesegang
50,595 PointsHolger Liesegang
50,595 PointsGlad I could help, Brendan Corey !
hamza shaikh
5,875 Pointshamza shaikh
5,875 Pointsjust want to lest you know i also was having trouble with the task 3 but you helped me out thankyou, but i'm a little confuse because in the video when added an array to the label he did not used self.
code worked fine even though i did'nt add self. to "[facts objectAtIndex:1]" it will really help me if you can clarify this for me thank you.
Holger Liesegang
50,595 PointsHolger Liesegang
50,595 PointsHi hamza shaikh !
https://teamtreehouse.com/forum/self-keyword might shed some light on the
self
topic.Michael Acosta Pegoraro
4,911 PointsMichael Acosta Pegoraro
4,911 PointsI was not aware about the self.shoppingList either. Good thing the answer was here and I found out after a while.