2

I cannot compile my iPhone project. In my CType.h I am getting the error:

Cannot find interface declaration for 'NSObject', superclass of 'CType'.

This results in a lot of others errors which are also in the same header file.

I have read that this could be due to a circular reference in my project. Therefore, I have tried to change many of my header imports to forward declarations. There are still some which I have not managed to make a forward declaration yet (e.g. if the class inherits from another class, then it needs the import and if I am using a delegate. There probably is a way around this, though).

I have been searching through my project multiple times but I have not managed to find the circular reference. Is there any tips or tricks to find a circular reference? I thought it would have something to do with my CType but it does not seem so.

EDIT:

This is my CType:

Interface:

#import <Foundation/Foundation.h>

@interface CType : NSObject

/*
 * Type ID
 */
@property (nonatomic, assign) NSInteger typeId;

/*
 * Type
 */
@property (nonatomic, strong) NSString *type;

/*
 * Initialize with type ID and type
 */
- (id)initWithId:(NSInteger)typeId type:(NSString *)type;

/*
 * Type with type ID and type
 */
+ (CType *)typeWithId:(NSInteger)typeId type:(NSString *)type;

@end

Implementation:

#import "CType.h"

@implementation CType

/* Create setters and getters */
@synthesize typeId;
@synthesize type;

/* Initialize with type ID and type */
- (id)initWithId:(NSInteger)_typeId type:(NSString *)_type
{
    if (self = [super init])
    {
        self.typeId = _typeId;
        self.type = _type;
    }

    return self;
}

/* Type with type ID and type */
+ (CType *)typeWithId:(NSInteger)typeId type:(NSString *)type
{
    return [[CType alloc] initWithId:typeId type:type];
}

@end
simonbs
  • 7,932
  • 13
  • 69
  • 115
  • I have updated my question to show `CType`. – simonbs Apr 30 '12 at 07:19
  • Have you tried cleaning and rebuilding? Also, have you tried naming the class from CType to something else? – Michael Frederick Apr 30 '12 at 07:56
  • Is your implementation module a .m? Do you have the prefix file properly configured? Sounds to me like your build environment is messed up somehow. Does a simpler case work? – Hot Licks Apr 30 '12 at 12:12
  • @MichaelFrederick I have tried cleaning and rebuilding without success. I have not yet tried renaming the class but I don't think `CType` is reserved in any way. – simonbs Apr 30 '12 at 13:21
  • @HotLicks My implementation is in an .m-file, yes. What do you mean with the configuration of the prefix file and what do you mean with "a simpler case"? – simonbs Apr 30 '12 at 13:21

1 Answers1

2

I tend to agree with @Hot Licks. This could very well be a corrupted file or a misconfiguration because theoretically there is nothing wrong with your code.

This is what I would suggest:

Create a new class (named something other than CType) and migrate your code over from CType to the new class. Then delete your old CType files. If things work at that point then rename your new class to CType and see what happens. Also, double check your apps prefix.pch file to see what headers are imported in there.

Michael Frederick
  • 16,664
  • 3
  • 43
  • 58
  • I have no idea why this error occurred. I did as you suggested, created a new file with a new name and moved the code from `CType` to the new class. No errors. Renaming it to `CType` gives me errors. I'm glad it works now but confused why this happened. – simonbs Apr 30 '12 at 18:32
  • I'm guessing that there's a `#define` for `CType` somewhere. Or it's a class defined in something included in the prefix file. – Hot Licks May 01 '12 at 12:10
  • may have been coincidence but I ran into this with CType and CTypeView being in the project... couldn't include the delegate in CTypeView, though clicking on it and 'show declaration' worked fine. Go figure. After renaming CType to BType it worked fine... – MobileVet Jan 01 '14 at 19:17