'CompletionHandler' 在此上下文中对于类型查找不明确
'CompletionHandler' is ambiguous for type lookup in this context
我最近加入了一个新项目并开始研究 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' 在此上下文中的类型查找中不明确
有谁知道如何解决这个问题?我四处搜索,找不到可行的解决方案。
改变
extension NetworkClientType {
typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void
至
extension NetworkClientType
where CompletionHandler == (Data?, URLResponse?, Error?) -> Void {
我最近加入了一个新项目并开始研究 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' 在此上下文中的类型查找中不明确
有谁知道如何解决这个问题?我四处搜索,找不到可行的解决方案。
改变
extension NetworkClientType {
typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void
至
extension NetworkClientType
where CompletionHandler == (Data?, URLResponse?, Error?) -> Void {