Home > Net >  Cannot assign to property of 'localVc' which is a get-only object?
Cannot assign to property of 'localVc' which is a get-only object?

Time:10-14

Like the code showed below, why swift cannot allow to assign a property of a readonly object? The readonly object 'localVc' have the set-write property "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
    }

}

CodePudding user response:

Change

public protocol HVSHomeVideoChildProtocol {
    var refreshGesture: UIPanGestureRecognizer! {get set}
}

To

public protocol HVSHomeVideoChildProtocol : AnyObject {
    var refreshGesture: UIPanGestureRecognizer! {get set}
}
  • Related