对于此上下文中的类型查找,“CompletionHandler”不明确

问题描述 投票:1回答:1

我最近加入了一个新项目并开始研究iOS应用程序代码库。但是,使用最新的Xcode 10,代码不再编译。

protocol NetworkClientType {
  associatedtype CompletionHandler
  static func intoRequest(_ url: URL?) -> URLRequest?
}

extension NetworkClientType {

  typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void

  static func intoIncompleteURLSessionDataTask(_ request: URLRequest) -> (CompletionHandler) -> URLSessionDataTask {
    return { completion in URLSession(configuration: .default).dataTask(with: request, completionHandler: completion) }
  }
}

然后在第10行(static func intoIncompleteURLSessionDataTask...),编译器错误说'CompletionHandler'对于此上下文中的类型查找是不明确的

有谁知道如何解决这个问题?我google了一下,找不到合适的解决方案。

ios swift swift4 xcode10 swift4.2
1个回答
2
投票

更改

extension NetworkClientType {
  typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void

extension NetworkClientType 
    where CompletionHandler == (Data?, URLResponse?, Error?) -> Void {
© www.soinside.com 2019 - 2024. All rights reserved.