2017-06-12 21 views
0

我想用我的自定義委託方法Alamofire的響應回調,如下圖所示:代表是Alamofire響應回調零

func startDownloadSegment() { 
    let destination: DownloadRequest.DownloadFileDestination = { _, _ in 
    let filePath = self.generateFilePath() 

    return (filePath, [.createIntermediateDirectories]) 
    } 

    // 1 
    print(self.delegate) 

    Alamofire.download(downloadURL, to: destination).response { response in 
    // 2 
    print(self.delegate) 

    if response.error == nil { 
     self.delegate?.segmentDownloadSucceeded(with: self) 
    } else { 
     self.delegate?.segmentDownloadFailed(with: self) 
    } 
    } 
} 

正如你可以看到,1號打印(self.delegate)返回委託我設置。但No.2總是返回nil,所以像downloadSucceeded(with :)這樣的委託方法不能被調用。

謝謝。

+0

您是否設置了委託? – NSNoob

+0

顯示更多代碼,委託實現部分也可能有所幫助 – dip

+0

@NSNoob是,委託已設置。我更新了我的問題。 –

回答

1

我找到了問題。問題是我設定的委託作爲

弱VAR代表

但隨着Alamofire響應回調,我應該省略「弱」關鍵字來完成它。