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

Khoi Vu
Khoi Vu
2,654 Points

Am I doing wrong with this question?

My code is:

self.shoppingCart.text = [shoppingList objectAtIndex:2];

#import "UIViewController.h"

@interface ViewController : UIViewController

@property (strong, nonatomic) NSString *shoppingCart;

@property (nonatomic, strong) NSArray *shoppingList;

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Add your code below!
    self.shoppingList = [[NSArray alloc] initWithObjects:@"toothpaste",@"bread", @"eggs",nil];
    self.shoppingCart.text = [shoppingList objectAtIndex:2];


1 Answer

Rashii Henry
Rashii Henry
16,433 Points

Hey Khoi,

There is simply no need for you to access the '.text' property of NSString. It doesn't have one! When you're assigning(=) a string a value to a string you wont have to access the text property, because it is already in text format from where you're grabbing it from.

Now a different case would be if you were taking user input in a textfield or text box. then you would self.textField.text and assign it somewhere else.

To make a long story short, remove the . text property and see what happens.