簡體   English   中英

無法分配給僅獲取對象的“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}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM