Sendability of function types in instance method 'dataTask(with:completionHandler:)' does not match requirement in protocol 'URLSessionProtocol'

huangapple go评论74阅读模式
英文:

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 { }

Sendability of function types in instance method 'dataTask(with:completionHandler:)' does not match requirement in protocol '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 { }

Sendability of function types in instance method 'dataTask(with:completionHandler:)' does not match requirement in protocol 'URLSessionProtocol'

答案1

得分: 1

typealias DataTaskResult = @Sendable (Data?, URLResponse?, Error?) -> Void
英文:

simple change it to

typealias DataTaskResult = @Sendable (Data?, URLResponse?, Error?) -> Void

huangapple
  • 本文由 发表于 2023年2月18日 16:10:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492023.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定