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

Forward declaration error in Crystal Ball app

I'm making good progress on the Crystal Ball app but I can't get past a few errors:

1) Receiver type 'AMCrystalBall' for instance message is a forward declaration

2) Receiver 'AMCrystalBall' for class message is a forward declaration

I feel as thought I've doubled-checked the code against the instructors code several times and can't figure out the error. I don't know how much of my code to post, so here it goes...

AMViewController.h --

#import <UIKit/UIKit.h>

@class AMCrystalBall;

@interface AMViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel      *predictionLabel;
@property (strong, nonatomic) AMCrystalBall *crystalBall;

- (IBAction)buttonPressed;

@end

AMViewController.m --

#import "AMViewController.h"

@interface AMViewController ()

@end

@implementation AMViewController

- (void)viewDidLoad
{
[super viewDidLoad];
self.crystalBall = [[AMCrystalBall alloc] init];


UIImage *backgroundImage = [UIImage   imageNamed:@"background"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:backgroundImage];
[self.view insertSubview:imageView atIndex:0];
}

- (void)didReceiveMemoryWarning
   {
    [super didReceiveMemoryWarning];
    }

- (IBAction)buttonPressed {
//int random =  arc4random_uniform(self.predictions.count);
//self.predictionLabel.text = [self.predictions objectAtIndex:random];
self.predictionLabel.text = [self.crystalBall randomPrediction];
}

@end

If anyone knows what the problem could be please help! I can post more code if needed, but I figured this was a good start. Thanks for all the help.

2 Answers

I'm most certain that you're getting those errors because you're using @class instead of an import statement.

Replace this line:

@class AMCrystalBall;

with this one:

#import "AMCrystalBall"

Your errors should go away :)

From what I'm finding on Google for that type of error... everything seems to be pointing to needing to import header files. Without seeing all of the other .h/.m files you have, I would suggest to double check that you're importing the header files everywhere you need to be... and double check camel-case spelling, sometimes it's easier to overlook.

Let me know what you find.