Swift扩展:添加where和协议遵从性
我可以这样做:Swift扩展:添加where和协议遵从性,swift,Swift,我可以这样做: extension Dictionary : MyProtocol {} extension Dictionary where Key: String, Value: Int {} 我可以做到: extension Dictionary : MyProtocol {} extension Dictionary where Key: String, Value: Int {} 但我不能这么做: extension Dictionary where Key: String,
extension Dictionary : MyProtocol {}
extension Dictionary where Key: String, Value: Int {}
我可以做到:
extension Dictionary : MyProtocol {}
extension Dictionary where Key: String, Value: Int {}
但我不能这么做:
extension Dictionary where Key: String, Value: Int : MyProtocol {}
或者这个:
extension Dictionary : MyProtocol where Key: String, Value: Int {}
正确的格式化方法是什么,允许我指定类型并指定遵守协议?好的,我是个白痴。刚刚意识到上一个示例给出了以下错误:
Extension of type 'Dictionary' with constraints cannot have an inheritance clause
所以这大概是不可能的。回答如下:
TLDR:这是不可能的
计划为Swift的未来版本提供:
关于如何实施的更多细节: