【发布时间】:2016-04-01 04:29:49
【问题描述】:
我有一个协议 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 要求。
【问题讨论】:
标签: ios swift generics swift2 swift-protocols