为什么在使用闭包创建属性时不允许使用self?

问题描述

// Design Protocol
protocol SendDataDelegate {}

// Design Sender/Delegator
class SendingVC {
    var delegate: SendDataDelegate?
    
    deinit {
        print("Delegator gone")
    }
}

// Design Receiver/Delegate
class ReceivingVC: SendDataDelegate {
    lazy var sendingVC: SendingVC = { // if i don't use lazy,i am not allowed to use self within the closure.
        let vc = SendingVC()
        vc.delegate = self // here
        return vc
    }()
    
    deinit {
        print("Delegate gone")
    }
}

这是什么原因? 根据我在网上发现的内容:由于没有初始化对象,因此自身不可用,这甚至意味着什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)