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

Coding Error, IOS, "creating a property"

This is my direct code, i have no idea why it is not succeeding when it's trying to build, if you could tell me what character is wrong, it would be very helpful!

//
//  ViewController.m
//  CrystalBall
//
//  Created by Owner on 12/25/12.
//  Copyright (c) 2012 com.toptechnow. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize PredictionLabel;

- (void)viewDidLoad

{
    [super viewDidLoad];
    predictionArray = [ [NSArray alloc] initWithObjects:@"It is certain","It is decidedly so" ,@"All signs say YES",
                                @"the stars are not aligned"
                                @"My reply is no",
                                @"It is doubtful",
                                @"Better not tell you now",
                                @"Concentrate and ask again",
                                @"Unable to answer now", nil];
}

- (void)viewDidUnload
{
    [self setPredictionLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    //Return Yes for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)ButtonPressed:(UIButton *)sender {

    self.PredictionLabel.text = [predictionArray objectAtIndex:3];
}
@end

2 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

@Landon have you defined predictionArray as a property in your interface?

It would be really helpful if you copy and paste the error that xCode is showing.

This line here:

predictionArray = [[NSArray ...

Would be instead:

self.predictionArray = [[NSArray ...

Because this property belongs to the implementation of ViewController, and we specify it with "self".

In this line:

"It is decidedly so"

you forgot to include the "@" sign, like this:

@"It is decidedly so"

In this line here:

self.PredictionLabel.text = [predictionArray objectAtIndex:3];

you wrote "PredictionLabel" and not "predictionLabel". The difference is that the first letter shouldn't be capitalized. Also, instead of "predictionArray", it's "self.predictionArray". The result:

self.predictionLabel.text = [self.predictionArray objectAtIndex:3];

These are the only mistakes I could see in the code, but I think I may have missed some of them. I'm just a beginner, if someone who has more experience with Objective-C can help, that would be really great.