NSURLDownload委托问题

时间:2015-09-06 01:25:13

标签: macos swift cocoa

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,delegate:ImageFetcher)' 我认为这与“自我”有关。我试图将其作为NSURLDownloadDelegate进行投射,但它抱怨它无法做到这一点。

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

将您的课程视为:

class ImageFetcher : NSObject, NSURLDownloadDelegate {

然后使用:

调用init行
var imageDownload = NSURLDownload(request: imageRequest, delegate: self)