我有一个协议RequestType,它有关联类型模型,如下所示.
public protocol RequestType: class {
associatedtype Model
var path: String { get set }
}
public extension RequestType {
public func executeRequest(completionHandler: Result<Model, NSError> -> Void) {
request.response(rootKeyPath: rootKeyPath) { [weak self] (response: Response<Model, NSError>) -> Void in
completionHandler(response.result)
guard let weakSelf = self else { return }
if weakSelf.logging { debugPrint(response) }
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试为所有失败的请求排队.
public class RequestEventuallyQueue {
static let requestEventuallyQueue = RequestEventuallyQueue()
let queue = [RequestType]()
}
Run Code Online (Sandbox Code Playgroud)
但我得到的错误是let queue = [RequestType](),Protocol RequestType只能用作通用约束,因为它具有Self或associatedType要求.