就像下面的代码一样,为什么swift不允许为只读对象赋值属性?只读对象localVc具有设置写入属性"refreshGesture"
public protocol HVSHomeVideoChildProtocol {
var refreshGesture: UIPanGestureRecognizer! {get set}
}
class HVSHomeLocalVideoController: HVSHomeVideoChildProtocol {
public var refreshGesture: UIPanGestureRecognizer!
}
typealias HVSHomeVideoController = (UIViewController & HVSHomeVideoChildProtocol)
@objc(HSAVideoHomeViewController)
class HSAVideoHomeViewController: UIViewController {
var refreshGesture: UIPanGestureRecognizer!
let singleLocalVc = HVSHomeLocalVideoController.init()
var localVc: HVSHomeVideoController {
return singleLocalVc
}
public override func viewDidLoad() {
super.viewDidLoad()
refreshGesture = UIPanGestureRecognizer.init(target: self, action: #selector(refreshGestureAction(sender:)))
localVc.refreshGesture = refreshGesture
}
}
变化
public protocol HVSHomeVideoChildProtocol {
var refreshGesture: UIPanGestureRecognizer! {get set}
}
public protocol HVSHomeVideoChildProtocol : AnyObject {
var refreshGesture: UIPanGestureRecognizer! {get set}
}