我在使用以下代码创建自己的 Moya 插件时遇到问题:
import Foundation
import Moya
import Result
public final class CustomPlugin: PluginType {
public func willSend(_ request: RequestType, target: TargetType) {
print("willSend")
}
public func didReceive(_ result: Result<Response, MoyaError>, target: TargetType) {
print("didReceive")
}
}
我从 Xcode 编译器中得到以下错误:
Generic type 'Result' specialized with too many type parameters (got 2, but expected 1)
我可以通过更改
来修复编译器错误public func didReceive(_ result: Result<Response, MoyaError>, target: TargetType)
到
public func didReceive(_ result: Swift.Result<Response, MoyaError>, target: TargetType)
但是在这个改变之后,didReceive 方法没有被调用。
谁能告诉我如何解决这个问题?
谢谢!
最佳答案
在 Moya 中,Result 被定义为一个通用枚举。
enum Result<T>{
case success(T)
case failure(String)
}
泛型参数类型只能是一个,但您已将两个参数作为结果应用到泛型。
关于ios - 自定义 Moya 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57254207/