Reputation: 2082
I'm trying to subclass URLSession
on iOS 10 using Xcode 8. I believe the Swift type system is getting confused, but I may be missing something:
class MyURLSession: URLSession {
// No errors
override func downloadTask(with request: URLRequest) -> URLSessionDownloadTask {
return URLSessionDownloadTask()
}
// No errors
override func downloadTask(with url: URL) -> URLSessionDownloadTask {
return URLSessionDownloadTask()
}
// See errors below
override func downloadTask(with request: URLRequest, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask {
return URLSessionDownloadTask()
}
// See errors below
override func downloadTask(with url: URL, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask {
return URLSessionDownloadTask()
}
}
error: method does not override any method from its superclass
override func downloadTask(with request: URLRequest, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask {
^
Foundation.URLSession:6:15: note: potential overridden instance method 'downloadTask(with:completionHandler:)' here
open func downloadTask(with request: URLRequest, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDownloadTask
^
Foundation.URLSession:7:15: note: potential overridden instance method 'downloadTask(with:completionHandler:)' here
open func downloadTask(with url: URL, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDownloadTask
^
/Users/pshah/Networking/Webservice.swift:108:19: error: method does not override any method from its superclass
override func downloadTask(with url: URL, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Void) -> URLSessionDownloadTask {
^
Foundation.URLSession:6:15: note: potential overridden instance method 'downloadTask(with:completionHandler:)' here
open func downloadTask(with request: URLRequest, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDownloadTask
^
Foundation.URLSession:7:15: note: potential overridden instance method 'downloadTask(with:completionHandler:)' here
open func downloadTask(with url: URL, completionHandler: @escaping (URL?, URLResponse?, Error?) -> Swift.Void) -> URLSessionDownloadTask
^
Upvotes: 1
Views: 775
Reputation: 2082
I figured it out. I have a Error
in my project, so had to qualify Error?
as Swift.Error?
in the methods with errors.
Upvotes: 1