看起来像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/