ios - Cannot assign self as delegate in property initializer -
i getting strange error message when try access self when initializing property on class. seems class has weird type.
this error:
cannot assign value of type 'viewcontroller -> () viewcontroller' value of type 'modelcontrollerdelegate?'
this code, simple example in playground:
import foundation import uikit protocol modelcontrollerdelegate { func modelcontrollerdidfinishtask() } class modelcontroller { var delegate : modelcontrollerdelegate? } class viewcontroller : uiviewcontroller, modelcontrollerdelegate { var modelcontroller : modelcontroller = { let controller = modelcontroller() controller.delegate = self return controller }() func modelcontrollerdidfinishtask() { } }
you trying use self
when not initialised. might work if use lazy initialisation:
lazy var modelcontroller : modelcontroller = { ...
Comments
Post a Comment