4

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!

Lior Pollak
  • 3,362
  • 5
  • 27
  • 48

2 Answers2

13

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)

Community
  • 1
  • 1
jere
  • 4,306
  • 2
  • 27
  • 38
0

After so many hours spending I found that, I have imported a some files in .h header file which was causing the import recursion.

How I fixed - I moved the same import in .m file and the build is successful.

Suggestion - Avoid class implementation imports in .h file.

Hope this helps!