NSURLDownload 委托问题
Posted
技术标签:
【中文标题】NSURLDownload 委托问题【英文标题】:NSURLDownload delegate issues 【发布时间】:2015-09-06 01:25:13 【问题描述】: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)
它在抱怨“找不到接受类型为 '(request: NSURLRequest, delegate: ImageFetcher)' 的参数列表的类型 'NSURLDownload' 的初始化程序 我相信这与“自我”有关。我试图将它转换为 NSURLDownloadDelegate 但它抱怨它不能这样做。
有什么建议吗?
【问题讨论】:
【参考方案1】:delcare 你的班级:
class ImageFetcher : NSObject, NSURLDownloadDelegate
然后调用 init 行:
var imageDownload = NSURLDownload(request: imageRequest, delegate: self)
【讨论】:
这样做给了我一个“类型'ImageFetcher'不符合协议'NSObjectProtocol'。在“类ImageFetcher:NSURLDownloadDelegate”行。这是否意味着我必须覆盖列出的所有必填字段developer.apple.com/library/mac/documentation/Foundation/… 通过“Class ImageFetcher : NSObject : NSURLDownloadDelegate 修复它以上是关于NSURLDownload 委托问题的主要内容,如果未能解决你的问题,请参考以下文章
How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
ERROR: Failed to set up Chromium r901912! Set “PUPPETEER_SKIP_DOWNLOAD“ env variable to skip downloa