Swift 警告:'weak' 不应应用于协议中的 属性 声明
Swift warning: 'weak' should not be applied to a property declaration in a protocol
看起来像 weak references will be disallowed in protocols。那么如果我想添加一个弱引用,我应该怎么做呢?有更好的主意吗?
protocol PipelineElementDelegate: class {
func someFunc()
}
protocol PipelineElement {
weak var delegate: PipelineElementDelegate? { get set}
}
只需从协议中删除 weak
关键字并在符合类型中将 属性 声明为弱:
class SomeClass: PipelineElement {
weak var delegate: PipelineElementDelegate?
}
看起来像 weak references will be disallowed in protocols。那么如果我想添加一个弱引用,我应该怎么做呢?有更好的主意吗?
protocol PipelineElementDelegate: class {
func someFunc()
}
protocol PipelineElement {
weak var delegate: PipelineElementDelegate? { get set}
}
只需从协议中删除 weak
关键字并在符合类型中将 属性 声明为弱:
class SomeClass: PipelineElement {
weak var delegate: PipelineElementDelegate?
}