class ImageFetcher {

    /* Initialize class variables and init function */


    func fetch(){

        var imageRequest = NSURLRequest(URL: self.source)
        var imageDownload = NSURLDownload(request: imageRequest, delegate: self)

        /* does path exist */
        let directoryPath = self.destination.stringByDeletingLastPathComponent
        let fileMgr = NSFileManager();
        fileMgr.createDirectoryAtPath(directoryPath, withIntermediateDirectories: true, attributes: nil, error: nil)

        imageDownload.setDestination(self.destination, allowOverwrite: true)
    }
}


我遇到的问题是生产线

var imageDownload = NSURLDownload(request: imageRequest, delegate: self)


它抱怨“无法找到类型为“ NSURLDownload”的初始化程序,该初始化程序接受类型为“(请求:NSURLRequest,委托:ImageFetcher)的参数列表”
我相信这与“自我”有关。我试图将其强制转换为NSURLDownloadDelegate,但它抱怨它无法做到这一点。

有什么建议么?

最佳答案

将您的课程声明为:

class ImageFetcher : NSObject, NSURLDownloadDelegate {

然后使用以下命令调用init行:
var imageDownload = NSURLDownload(request: imageRequest, delegate: self)

关于macos - NSURLDownload委托(delegate)问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32419162/

10-12 02:07