xcode 未知类型名称而已知?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12283685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:25:01  来源:igfitidea点击:

Unknown type name while known?

iosxcode

提问by Lior Pollak

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

Xcode 突然显示了这个错误:“未知类型名称”

I'll explain: My StoriesViewController.h:

我会解释:我的 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:

在我的 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:

在我的 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.

NB @class 引发了大量的 ARC 问题。

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

我已经删除了对 ViewController.h 的无用引用,成功了。解决了!

回答by jere

You have a circular referenceproblem.

你有一个循环引用问题。

What's happening is that when you load your ViewControllerit 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.

发生的事情是,当您加载ViewController它时,它会通过它的导入,它会加载Stories.h,它会加载它的导入并返回到ViewController.h,因此您陷入了无限循环。

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

要么删除冲突的导入之一,要么使用前向类声明(该示例适用于 C++,请参阅此处的 Objective-C 示例)