使用 Swift 协议时短路 [英] Short-circuit when using a Swift protocol

查看:29
本文介绍了使用 Swift 协议时短路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,不可能在 -Header.h 中的文件中包含接口头文件.我的实际问题是我定义了一个 Swift 协议的第一类协议:

As known, it is not possible to include the interface header file from a file in the -Header.h. My actual problem is that I have the definition of a class one protocol of which is a Swift one:

@protocol arrivingDelegate;

@interface palettaTraffic : NSObject<MKMapViewDelegate, arrivingDelegate> {
}

如果我导入 *-Swift.h 文件,当该文件包含在另一个包含在头文件中的文件中时,我会进入丑陋的循环.

If I import the *-Swift.h file I get into the ugly cycle when the file is included in another one that is included in the header file.

当我使用@protocol 指令时会发生这种情况:这是一个警告,但非常令人不安.

This is what happens when I use the @protocol directive: it is a warning, but quite a disturbing one.

swift 协议是这样定义的:

This is how the swift protocol is defined:

@objc public protocol arrivingDelegate {
    func submitManualBusLine(busStripe:StripeProtocol)
}

我也发现了一个类似的帖子:Objective-C 类中的 Swift 协议

I also found a similar post: Swift protocol in Objective-C class

但这些建议似乎都不适用.

But none of the suggestions seem to apply.

推荐答案

在 Objective-c 中采用 swift 协议是一个棘手的过程.我也通过将采用类移植到 Swift 解决了这个问题.

Adopting swift protocols in Objective-c is a tricky process. I fixed the issue by porting the adopting class to Swift too.

这篇关于使用 Swift 协议时短路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆