boo*_*oog 7 protocols weak-references swift
看起来协议中不允许使用弱引用.那么,如果我想添加一个弱引用,我该怎么办呢?有什么好主意吗?
protocol PipelineElementDelegate: class {
func someFunc()
}
protocol PipelineElement {
weak var delegate: PipelineElementDelegate? { get set}
}
Run Code Online (Sandbox Code Playgroud)
zou*_*oul 16
只需weak从协议中删除关键字,然后在符合类型中将属性声明为弱:
class SomeClass: PipelineElement {
weak var delegate: PipelineElementDelegate?
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2057 次 |
| 最近记录: |