无法分配给 'localVc' 的 属性 这是一个只获取对象?
Cannot assign to property of 'localVc' which is a get-only object?
就像下面显示的代码,为什么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}
}
就像下面显示的代码,为什么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}
}