协议中的方法返回了另一个协议,该协议具有associatedType“只能用作通用”错误

时间:2018-10-22 20:53:32

标签: ios swift generics protocols associated-types

我在协议中创建了一个方法,该方法返回了另一个协议。当我尝试在此返回的协议中使用关联方法时,我收到有关以下错误的信息:Protocol 'CoordinteProtocol' can only be used as a generic constraint because it has Self or associated type requirements

这是我的示例代码:

protocol CoordinteProtocol {
    associatedtype Result
    func getCoords() -> Result?
}

protocol LocationProtocol  {
    func getLocationWith() -> CoordinteProtocol? //error -> Protocol 'CoordinteProtocol' can only be used as a generic constraint because it has Self or associated type requirements
}

是否有可能解决此问题?

0 个答案:

没有答案