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 trialChristian Johansson
1,772 PointsI really can't seem to grasp this either
I'm trying to understand how this work but don't seem like i can grasp it at the moment.
#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];
// Add your code below!
self.shoppingList = @[@"toothpaste", @"bread", @"eggs"];
self.shoppingCart = [shoppingList objectAtIndex:2];
}
@end
Christian Johansson
1,772 PointsWell I wrote self.shoppingCart = [shoppingList objectAtIndex:2]; and I thought that would work. But it seems I don't understand the fundementals.
2 Answers
Damien Watson
27,419 PointsAh, you are missing the 'self.' from shoppingList, try:
self.shoppingCart = [self.shoppingList objectAtIndex:2];
Christian Johansson
1,772 PointsNow it worked! Hm, don't really know if I should just switch to swift instead since it doesn't seem like I can understand objective C
Damien Watson
27,419 PointsThat is an interesting point, very worth considering. I have been coding in Objective C for around 4 years now. Since Apple is not going to be supporting it and moving ahead with swift...?
I know a company down here that won't employ you if you don't know swift, no matter how many years ObjC.
Christian Johansson
1,772 PointsInteresting, but I do wanna learn objective C but maybe it's easier for me to start with swift so I get stuff going. I think I learn best by making stuff and having fun!
Damien Watson
27,419 PointsHaving something to build does make it a lot easier. With ObjC, just remember that any variable declared in your header file '.h' needs to be accessed in the implementation file '.m' by putting 'self.' at the front and you should be alright. :)
Damien Watson
27,419 PointsDamien Watson
27,419 PointsHi Christian, I started writing a massive response to this, then realised I didn't actually understand what your problem is. Can you be a little more specific? eg:
I'm happy to get verbose on this, just want to make sure I'm answering your question. :)