How to pass a local function to another object during init?

前端 未结 3 1298
悲&欢浪女
悲&欢浪女 2021-01-29 11:09

How to pass a local function to another object during init?

I did the below, but got \'self\' captured by a closure before all members were initialized

<
3条回答
  •  礼貌的吻别
    2021-01-29 11:28

    You have to call super.init() before:

    class ContextViewController: UIHostingController {
    
        let drawViewWrapper: ContentView?
        
        init(drawView: CustomDrawView) {
            super.init(rootView: self.drawViewWrapper)
            self.drawViewWrapper = ContentView(
                drawView: drawView,
                dismiss: { self.dismiss(animated: true) })
        }
    
    }
    

提交回复
热议问题