为什么这个协议“只能用作通用约束”? [英] Why can this protocol "only be used as a generic constraint"?

查看:205
本文介绍了为什么这个协议“只能用作通用约束”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protocol ProtocolWithAlias {
typealias T
}

协议AnotherProtocol {
func someFunc() - > ProtocolWithAlias
}

但是我得到错误: Protocol'ProtocolWithAlias '只能用作通用约束,因为它具有自我或相关类型需求



是否可以做类似这样的事情?错误消息(或者至少仅用作通用约束部分)似乎对我没有多大意义。



我正在使用最新的Xcode 6 beta 3。

谢谢!

解决方案

试试这个:

  func someFunc< T:ProtocolWithAlias>() - > T 


I'm attempting to do the following in Swift:

protocol ProtocolWithAlias {
    typealias T
}

protocol AnotherProtocol {
    func someFunc() -> ProtocolWithAlias
}

But I get the error: Protocol 'ProtocolWithAlias' can only be used as a generic constraint because it has Self or associated type requirements.

Is it possible to do something like this? The error message (or at least the "only be used as a generic constraint" part) doesn't seem to make much sense to me.

I'm using the latest Xcode 6 beta 3.

Thanks!

解决方案

Try this:

func someFunc<T:ProtocolWithAlias>() -> T

这篇关于为什么这个协议“只能用作通用约束”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆