【发布时间】:2017-07-28 08:42:53
【问题描述】:
挣扎了一段时间,如果您能对此有所了解,那将非常有帮助:
我有一个APIWorkerProtocol,它有一个属性要求,所需的属性是一个协议,即DataParserProtocol
protocol APIWorkerProtocol {
var apiRequestProvider : APIRequestGeneratorProtocol {get}
var dataParser : DataParserProtocol{get}
func callAPI(completionHandler: @escaping (APICallResult<Self.ResultType>) -> Void)
}
protocol DataParserProtocol {
associatedtype ExpectedRawDataType
associatedtype ResultType
func parseFetchedData(fetchedData : ExpectedRawDataType) -> APICallResult<ResultType>
}
我怎样才能做到这一点?
在当前的实现中,这会导致错误Protocol 'DataParserProtocol' can only be used as a generic constraint because it has Self or associated type requirements。
提前致谢
Ankit
【问题讨论】:
标签: ios swift generics protocols