[swift-users] Cannot implement NSURLSessionDownloadDelegate
jordan_rose at apple.com
Tue Mar 22 11:55:40 CDT 2016
> On Mar 22, 2016, at 8:49, Sebastian Hagedorn via swift-users <swift-users at swift.org> wrote:
> I have started migrating a Swift 2.2 project to Swift 3.0 using the latest dev snapshot (16 March 2016) and Xcode 7.3.
> I have an existing class (and have verified the same behaviour in a new, isolated test project) that declares to conform to NSURLSessionDownloadDelegate (and inherits from NSObject). However, I cannot satisfy the compiler as I get the following error:
>> .../SessionDel.swift:11:7: Type 'MyDelegate' does not conform to protocol 'NSURLSessionDownloadDelegate'
>> .../Foundation.NSURLSessionDownloadDelegate:3:17: Protocol requires function 'urlSession(_:downloadTask:didFinishDownloadingTo:)' with type '(NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingTo: NSURL) -> Void’
>> .../SessionDel.swift:13:10: Objective-C method 'urlSession:downloadTask:didFinishDownloadingTo:' provided by method 'urlSession(_:downloadTask:didFinishDownloadingTo:)' does not match the requirement's selector ('URLSession:downloadTask:didFinishDownloadingToURL:’)
> The signature that Xcode’s autocompletion suggests is this:
>> func urlSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingTo location: NSURL)
> …which is slightly different from the one in the error message (the first parameter), but neither works. I’ve also tried several variants with regard to capitalization and truncation of parameter names, but cannot get this to compile. Is this a known/temporary issue in the current snapshot, or should I file a bug report?
Note the error message carefully: the method you implemented has the right name in Swift, but "does not match the requirement's selector". You can manually control the selector using the 'objc' attribute, i.e. `@objc(URLSession:downloadTask:didFinishDownloadingToURL:)`.
Doug is looking at inferring selector names from the protocols you conform to, though it'll probably be limited in some way so that we don't do a huge amount of extra work.
More information about the swift-users