草庐IT

tempHandler

全部标签

swift - 在 swift 中将函数用作 block 时避免保留循环

以下是您可以在playground中运行的代码示例importFoundationclassTempNotifier{varonChange:(Int)->Void={tin}varcurrentTemp=72init(){//1.onChange={[unownedself]tempinself.currentTemp=temp}//2.onChange={[unownedself]tempinself.tempHandler(temp)}//3.unownedlets=selfonChange=s.tempHandler}deinit{println("deinit")}priva