views:

16295

answers:

6

Hi guys. Whenever I build the following code, I get the error above.

//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h";

@interface Controller : NSObject
{
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet PolygonShape *shape;
    IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end


//Controller.m
#import "Controller.h"


@implementation Controller
@end

However, when I replace the import statement and put a forward class reference instead, the code compiles.

//Controller.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
@class PolygonView;

@interface Controller : NSObject
{
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet PolygonShape *shape;
    IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end

//Controller.m
#import "Controller.h"
#import "PolygonView.h"

@implementation Controller
@end

Can anyone explain?

A: 

Question was answered in the comments.

Ridwan
+4  A: 

Yes, I too had this problem of Cyclical Dependencies where I was importing both classes in each other. I also didn't know what Forward Declarations were. I promptly searched it on Wikipedia but it was poorly described. I found this post that explains what they are and how they relate to cyclical imports. http://timburrell.net/blog/2008-11-23/effective-c-cyclical-dependencies/

ChrisJF
A: 

this happens because u forgot to include one of the header files. iwas also getting same kinda error but after proper inclusion of header file error went off.

meet bhatha
+1  A: 

I got this error with a simple mistake... perhaps others are doing likewise?

CORRECT:

@interface ButtonDevice : NSObject 

{

    NSString *name;
    NSString *uri;
    NSString *icon;
}

    @property (nonatomic, retain) IBOutlet NSString *name;
    @property (nonatomic, retain) IBOutlet NSString *uri;
    @property (nonatomic, retain) IBOutlet NSString *icon;
@end

WRONG:

@interface ButtonDevice : NSObject 
{

    NSString *name;
    NSString *uri;
    NSString *icon;

    @property (nonatomic, retain) IBOutlet NSString *name;
    @property (nonatomic, retain) IBOutlet NSString *uri;
    @property (nonatomic, retain) IBOutlet NSString *icon;
}   
@end
Dan Brickley
A: 

I had a similar problem but now I've got it fixed (I think) thanks to Ridwan and the rest of you guys.

Thanks a lot!

Mister Mida
A: 

THANKS!! Just has to include a class which seemed to be overlooked:

import "NameOfClass.h"

and it was sorted :)

Smotyn