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 trial

iOS Build a Simple iPhone App with Objective-C Creating a Data Model Creating a Data Collection

what does it mean to add the property to the header file?

I am so confused??

ViewController.h
#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@end
ViewController.m
#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *shoppingList = @[@"nonatomic", @"strong"];
}

@end

1 Answer

Nathan Tallack
Nathan Tallack
22,159 Points

So 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. ;)