Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown type name while known?

Tags:

xcode

ios

Xcode has showed out of the blue this error: "Unknown type name"

I'll explain: My StoriesViewController.h:

#import <UIKit/UIKit.h>
#import "Stories.h"

@interface StoriesViewController : UIViewController <UITextViewDelegate>

@property (strong) Stories *story; //Here it goes- "Unknown type name `Stories`"
@property (weak) IBOutlet UITextView *storyView;
@end

In my Stories.h:

#import <UIKit/UIKit.h>
#import "ViewController.h"

@interface Stories : UIDocument


@property (strong) NSString * storyContent;

@end

Again, out of the blue.

Thanks in advance.

EDIT:

In my ViewController.h:

#import <UIKit/UIKit.h>
#import "Stories.h"
#import "StoriesViewController.h"
#import "StoriesPickerViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController : UIViewController <UITextFieldDelegate,  UIAlertViewDelegate> {

}


@end

NB @class throws loads of ARC issues.

I have removed useless references to ViewController.h, worked. SOLVED!

like image 664
Lior Pollak Avatar asked Dec 12 '22 22:12

Lior Pollak


1 Answers

You have a circular reference problem.

What's happening is that when you load your ViewController it goes through it's imports, it loads Stories.h, it goes to load it's imports and it goes back to ViewController.h, so you are stuck in an infinite loop there.

Either remove one of the conflicting imports, or use forward class declaration (that example is for C++, see here for an example with Objective-C)

like image 100
jere Avatar answered Dec 14 '22 10:12

jere