最佳答案
我有一个 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) }
}
}
}
现在,我尝试为所有失败的请求创建一个队列。
public class RequestEventuallyQueue {
static let requestEventuallyQueue = RequestEventuallyQueue()
let queue = [RequestType]()
}
但是我在 let queue = [RequestType]()
行得到一个错误: Protocol RequestType 只能用作通用约束,因为它具有 Self 或 AssociatedType 需求。