gpt4 book ai didi

ios - Objective C 类找不到 Swift 协议(protocol)的定义

转载 作者:搜寻专家 更新时间:2023-10-30 22:18:24 24 4
gpt4 key购买 nike

我有一个 Swift 协议(protocol),像这样:

@objc protocol Linkable {
func presentLink(link: MyLink)
}

我还有一个 Objective-C 类,它不适合这个协议(protocol):

@protocol Linkable;

@interface MyDetailViewController : MyTableViewController <Linkable>

etc...

据我所知,我已经正确地声明了该协议(protocol),该协议(protocol)具有 @objc 符号,并且我将其放入 Objective C 类的接口(interface)声明中,但是我'我仍然在 @interface 开头的行收到警告。

警告说:“找不到‘Linkable’的协议(protocol)定义。”

奇怪的是,它构建并运行,并且按预期工作,但如果 Linkable 实际上没有问题,为什么会出现警告?是否有不同的方式来声明协议(protocol)或遵守协议(protocol)以清除警告?

这是否只是 Xcode 中措辞不当的警告之一?如果是,实际发生了什么?

编辑

这是一个自包含的示例项目,它有同样的错误:https://github.com/thinkfishhook/Swift-ObjC_Protocol

最佳答案

#import "ViewController.h"
#import "Protocol_WTF-Swift.h"

@interface ViewController () <MyProtocol>

@end

@implementation ViewController

- (void)doTheThings {
// doing the things
}

@end

关于ios - Objective C 类找不到 Swift 协议(protocol)的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42541457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com