如何在Swift中传递弱委托作为函数参数?

时间:2016-01-13 11:02:17

标签: ios swift delegates ios9 retain-cycle

我将委托对象作为函数args传递,如下所示:

private func sendHttpRequest(request:NSURLRequest,netWorkDelegate:NetWorkDelegate){
    let queue = NSOperationQueue();
    NSURLConnection.sendAsynchronousRequest(
        request,
        queue: queue,
        completionHandler: {
            response, data, error in
            dispatch_async(dispatch_get_main_queue(), {

                if(error != nil){
                    //then delegate connection error
                    if netWorkDelegate.handleError != nil {
                        netWorkDelegate.handleError!()
                    }

                }
          }
     }

我不确定这是否会保留对该委托的强引用,并且会阻止在执行该块之前释放该对象!

这样安全吗?

0 个答案:

没有答案