【发布时间】:2020-11-03 01:11:09
【问题描述】:
XCode 12.1
此项目目标在添加伞头后出现编译器错误add swift functionality to an existing objective c target
现在所有目标现有的各种<ComposeDelegate> 声明都出现No type or protocol named '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
其他类似的代码错误也会出现在目标代码的其他地方。
如何解决这个问题?
【问题讨论】:
-
警告和错误弹出,因为它已经在其他地方定义了。预编译器会忽略声明,因此会弹出更多错误。猜测是
@class ComposeDelegate;,这有点过头了。 -
提示:一般来说,当您收到警告或错误时 - 不足为奇 - 错误/错误必须高于代码或项目设置中的警告。因此,在搜索问题时,您始终可以使用
//或/* ... */来注释某些行并查看更改。 -
提示 2:
/*<UITextViewDelegate>*/在直接跟在 ClassName 之后是“危险的”。在注释掉的代码之前直接换行。 -
这实际上取决于在哪里、如何以及什么样的桥接头。假设 Objc 桥接到 Swift。除了项目设置之外,您不会在任何地方重新导入标题。否则,您将创建一个乒乓球游戏。桥接标头当然可以包含其他桥接标头,但到目前为止我记得每个项目都使用一个标头。
标签: ios objective-c swift xcode