gpt4 book ai didi

swift - 子类 URLSession iOS 10

转载 作者:行者123 更新时间:2023-11-28 06:34:10 26 4
gpt4 key购买 nike

我正在尝试使用 Xcode 8 在 iOS 10 上对 URLSession 进行子类化。我相信 Swift 类型系统越来越困惑,但我可能遗漏了一些东西:

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
^

最佳答案

我想通了。我的项目中有一个 Error,所以必须在有错误的方法中将 Error? 限定为 Swift.Error?

关于swift - 子类 URLSession iOS 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39514787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com