Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing class: Cannot find superclass

I have ForceGaugeViewController class and ForceGaugeController class. I'm trying to make the ForceGaugeController class be a subclass of ForceGaugeViewController, but I'm receiving errors.

Error:

Cannot find interface declaration for ForceGaugeViewController superclass of ForceGaugeController class.

ForceGaugeViewController.h

#import <UIKit/UIKit.h>
#import <math.h>
#import "HardwareController.h"
#import "ForceGaugeController.h"

@interface ForceGaugeViewController : UIViewController{
}
end

ForceGaugeViewController.m

#import "ForceGaugeViewController.h"

@implementation ForceGaugeViewController

ForceGaugeController.h

#import <Foundation/Foundation.h>
#import "ForceGaugeViewController.h"
#import "FMDatabase.h"
#import "FMResultSet.h"

@class ForceGaugeViewController;

// error here
@interface ForceGaugeController : ForceGaugeViewController{
}
@end

ForceGaugeController.m

#import "ForceGaugeController.h"
like image 748
ilaunchpad Avatar asked Sep 01 '26 23:09

ilaunchpad


2 Answers

You can not only forward reference a class that you will inherit from or a protocol that you will implement. You just need to import the superclass in the header which you are already doing and then remove the @class declaration.

Edit: Also the superclass ForceGaugeViewController should not include the subclass ForceGaugeViewController in the header file.

ForceGaugeController.h

#import <Foundation/Foundation.h>
#import "ForceGaugeViewController.h"
#import "FMDatabase.h"
#import "FMResultSet.h"

@interface ForceGaugeController : ForceGaugeViewController{
 }
@end
like image 80
Joe Avatar answered Sep 03 '26 14:09

Joe


Be sure to avoid circular imports: Make sure you do not import any of the header or implementation subclasses files into the superclass file where the superclass interface declaration is (.h file)

like image 27
asaf am Avatar answered Sep 03 '26 14:09

asaf am



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!