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 :)這樣的委託方法不能被調用。
謝謝。
您是否設置了委託? – NSNoob
顯示更多代碼,委託實現部分也可能有所幫助 – dip
@NSNoob是,委託已設置。我更新了我的問題。 –