英文:
Sendability of function types in instance method 'dataTask(with:completionHandler:)' does not match requirement in protocol 'URLSessionProtocol'
问题
我在编写URLSessionProtocol时收到下面的警告。可能的原因是什么?
protocol URLSessionProtocol {
typealias DataTaskResult = (Data?, URLResponse?, Error?) -> Void
func dataTask(with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTask
}
extension URLSession: URLSessionProtocol { }
英文:
I am getting below warning while writing URLSessionProtocol.
What could be the reason?
protocol URLSessionProtocol {
typealias DataTaskResult = (Data?, URLResponse?, Error?) -> Void
func dataTask(with request: URLRequest, completionHandler: @escaping DataTaskResult) -> URLSessionDataTask
}
extension URLSession: URLSessionProtocol { }
答案1
得分: 1
typealias DataTaskResult = @Sendable (Data?, URLResponse?, Error?) -> Void
英文:
simple change it to
typealias DataTaskResult = @Sendable (Data?, URLResponse?, Error?) -> Void
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论