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 trialJessie Cui
7,607 Pointswhat does it mean to add the property to the header file?
I am so confused??
#import "UIViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) NSString *shoppingCart;
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *shoppingList = @[@"nonatomic", @"strong"];
}
@end
1 Answer
Nathan Tallack
22,160 PointsSo when you create a property inside a class file (that's your .m file) you want to declare it inside your header file also so that other parts of your code that load the header will understand the property is there inside the class file without having to parse the class file.
So by looking at the header only you can see there is a property of shoppingCart, which is an NSString, that is a member of the class ViewController. And your compiler (and more importantly you) did not need to parse the whole class file to know that.
Do note the discrepency in your code though. In your header you say the shoppingCart property is an NSString type, and in the class you declaring it as an NSArray type. That would be a problem. ;)