swift 警告 : 'weak' should not be applied to a property declaration in a protocol

标签 swift protocols weak-references

看起来像weak references will be disallowed in protocols .那么如果我想添加一个弱引用,我应该怎么做呢?有更好的主意吗?

protocol PipelineElementDelegate: class {
    func someFunc()
}
protocol PipelineElement {
    weak var delegate: PipelineElementDelegate? { get set}
}

最佳答案

只需从协议(protocol)中删除 weak 关键字,并在符合类型中将属性声明为 weak 即可:

class SomeClass: PipelineElement {
    weak var delegate: PipelineElementDelegate?
}

关于 swift 警告 : 'weak' should not be applied to a property declaration in a protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50772175/

相关文章:

go - Sec-Websocket-Protocol 问题

ios - 如何在另一个函数中访问以编程方式创建的 subview

protocols - super 终端使用什么通讯协议(protocol)?

ios - Xcode 8.1 UI 测试 twoFingerTap() 在谷歌地图 View 上失败

iOS 传递数据、单例、外部或通过协议(protocol)?

iphone - 关于弱引用和保留循环的说明

arrays - 自删除数组元素(一旦它们变得未定义)

swift - 是否需要在单例类中使用弱引用?

SwiftUI - 按下按钮和导航时带有错误消息的表单

ios - 如何在操作表样式的 UIAlertController 中具有多种突出显示颜色?