我有一个协议RequestType,它具有如下的relatedType模型。
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要求,因此只能用作通用约束。