【发布时间】:2020-02-25 02:27:34
【问题描述】:
我已经设置了一个协议来将一些信息发送回之前的 VC。
我是这样定义的:
protocol FilterViewControllerDelegate: class {
func didSearch(Parameters:[String: String]?)
}
但是使用时有什么区别:
protocol FilterViewControllerDelegate {
func didSearch(Parameters:[String: String]?)
}
我什么时候应该使用: class 协议?
【问题讨论】:
-
取决于符合
FilterViewControllerDelegate的所有内容是否为class,并且您希望将类型为FilterViewControllerDelegate的内容视为具有引用语义(例如,这将允许您使用weak属性,我怀疑您可能需要)。例如:swift protocol 'weak' cannot be applied to non-class type.
标签: swift swift-protocols