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 trialJames Rowe
2,551 PointsNot understanding what I am doing wrong with question 3 of 3 in 'Creating a Data Collection'
Ive tried a couple of methods, but now I feel I'm just stumbling around in the dark.
#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 = [[NSArray alloc] initWithObjects: @"toothpaste", @"bread", @"eggs", nil];
self.shoppingCart = [self.shoppingList objectsAtIndex:2];
}
@end
2 Answers
kasaltrix
9,491 PointsHi James,
You are almost there at completing your challenge. There is a minor mistake with the method 'objectsAtIndex' which should be replaced by 'objectAtIndex' leading to the correct method call.
self.shoppingCart = [self.shoppingList objectAtIndex:2];
Hope this helps :)
Caleb Kleveter
Treehouse Moderator 37,862 PointsYou might need to use an underscore vs. self:
self.shoppingCart = [_shoppingList objectAtIndex:2];
kasaltrix
9,491 PointsWell you can use the instance variable (ivar) to call a method as mentioned above but I recommend not to use it for that purpose because ivars are basically used for initializing a property under the designated initializer rather than calling class methods. I guess I am going the right way?
James Rowe
2,551 PointsJames Rowe
2,551 PointsThank you so much! That worked... though its frustrating that it was something so simple, after spending so much time on it. Live & learn.
kasaltrix
9,491 Pointskasaltrix
9,491 PointsI am glad you figured it out :)