2016-09-15 16 views
0

私はスウィフト型システムが混乱していると考えているのXcode 8を使用してiOSの10にURLSessionをサブクラス化しようとしているが、私は何か欠けていることがあります。私はそれを考え出したサブクラスURLSession iOSの10

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 
      ^

答えて

0

を。私のプロジェクトにはErrorがありますので、Error?Swift.Error?としてエラーのあるメソッドで修飾する必要がありました。