Ios 没有名为'的类型或协议;复合闸门';添加桥接标头后出错

Ios 没有名为'的类型或协议;复合闸门';添加桥接标头后出错,ios,objective-c,swift,xcode,Ios,Objective C,Swift,Xcode,XCode 12.1 此项目目标在添加伞形头后获取编译器错误 现在,在所有目标现有的各种声明上都出现了一个名为“ComposeDelegate”的类型或协议错误 ComposeViewController.h @class ComposeViewController; @class DataModel; @class Message; // The delegate protocol for the Compose screen @protocol ComposeDelegate <N

XCode 12.1

此项目目标在添加伞形头后获取编译器错误

现在,在所有目标现有的各种
声明上都出现了一个名为“ComposeDelegate”的类型或协议错误

ComposeViewController.h

@class ComposeViewController;
@class DataModel;
@class Message;

// The delegate protocol for the Compose screen
@protocol ComposeDelegate <NSObject>
- (void)didSaveMessage:(Message*)message atIndex:(int)index;
@end

// The Compose screen lets the user write a new message
@interface ComposeViewController : UIViewController /*<UITextViewDelegate>*/

@property (nonatomic, assign) id<ComposeDelegate> delegate;
@property (nonatomic, strong) DataModel* dataModel;
@property (nonatomic, strong) AFHTTPClient *client;
@end
ComposeViewController.h
@类ComposeViewController;
@类数据模型;
@类消息;
//撰写屏幕的委托协议
@协议组合网关
-(void)didSaveMessage:(Message*)Message atIndex:(int)index;
@结束
//撰写屏幕允许用户编写新消息
@接口组件视图控制器:UIViewController/**/
@属性(非原子,赋值)id委托;
@属性(非原子,强)数据模型*数据模型;
@财产(非原子、强)AFHTTPClient*客户;
@结束

其他类似的代码错误也出现在目标代码的其他地方


如何解决这个问题?

为您的协议创建一个文件,并将协议声明复制到该文件中

// ComposeDelegate.h

#idndef ComposeDelegate_h
#define ComposeDelegate_h

// The delegate protocol for the Compose screen
@protocol ComposeDelegate <NSObject>
- (void)didSaveMessage:(Message*)message atIndex:(int)index;
@end

#endif
//ComposeDelegate.h
#idndef复合闸门
#定义ComposeDelegate_h
//撰写屏幕的委托协议
@协议组合网关
-(void)didSaveMessage:(Message*)Message atIndex:(int)index;
@结束
#恩迪夫
然后使用此文件包括您想要的任何位置。 虽然创建一个额外的文件似乎是额外的工作,但它使您能够更好地控制源代码的预处理

#ifndef SomeName\u h
<代码>#endif防止代码执行两次


PS:如果您编写了一个
@接口
,并且声明的类没有在前面/上面使用,那么如果不是真的需要,您不必也不应该预先声明类名(
@Class ComposeDelegate;
)。

警告和错误会弹出,因为它已经在其他地方定义了。预编译器忽略声明,因此会弹出更多错误。猜测是
@class ComposeDelegate/
/**/
注释某些行并查看更改。提示2:
/***/
直接跟在类名后面时是“危险的”。在注释代码之前直接换行。这实际上取决于桥接头的位置、方式和类型。假设Objc桥接到Swift。除了项目设置之外,您不会在任何地方重新导入标题。否则,您将创建一个乒乓球游戏。桥接头当然可以包含其他桥接头,但到目前为止,我记得每个项目都使用一个头。将协议放入其中,并将其导入有错误的文件中。仍然会出错。还是很困惑。