Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Swift委托_Swift_Delegates - Fatal编程技术网

使用Swift委托

使用Swift委托,swift,delegates,Swift,Delegates,我正在用swift为NSOperation编写一个子类。然而,我遇到了一个奇怪的问题 class Downloader : NSOperation, NSURLSessionDelegate, NSURLSessionDownloadDelegate{} 当我添加“NSURLSessionDownloadDelegate”时,它将显示一个错误:“类型'Downloader'不符合协议'NSURLSessionDownloadDelegate'” 当我删除它时,一切都正常。 你知道为什么

我正在用swift为NSOperation编写一个子类。然而,我遇到了一个奇怪的问题

 class Downloader : NSOperation, NSURLSessionDelegate,    NSURLSessionDownloadDelegate{}
当我添加“NSURLSessionDownloadDelegate”时,它将显示一个错误:“类型'Downloader'不符合协议'NSURLSessionDownloadDelegate'” 当我删除它时,一切都正常。 你知道为什么吗? 谢谢,前进

根据苹果文档

实施 URLSession:downloadTask:DidFinishDownloadingTour: 是必要的,


请确保您已经实现了它。

您需要实现在
nsurlsessiondownloaddegate
中标记为必需的方法是的,这是真的。在我使用Object-C之前,如果我没有实现这个方法,它在编译之前是没有错误的。Swift与Objcet-C不同。谢谢!