相关疑难解决方法(0)

协议只能用作通用约束,因为它具有Self或associatedType要求

我有一个协议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要求.

generics ios swift swift-protocols swift2

73
推荐指数
6
解决办法
3万
查看次数

标签 统计

generics ×1

ios ×1

swift ×1

swift-protocols ×1

swift2 ×1