Swift 如何从顺序嵌套的类型定义输出类型

Swift 如何从顺序嵌套的类型定义输出类型,swift,Swift,我想做一个目录的扩展名。我的结构是: var points:[String:Set<Double>] = ["x":[0.0, 2.0, 4.0, 6.0], "y":[10.0, 20.0, 30.0], z":[100.0, 200.0]] 因此,在这种特殊情况下,扩展标头将如下所示: extension Dictionary where

我想做一个目录的扩展名。我的结构是:

var points:[String:Set<Double>] = ["x":[0.0, 2.0, 4.0, 6.0],
                                   "y":[10.0, 20.0, 30.0],
                                   z":[100.0, 200.0]]
因此,在这种特殊情况下,扩展标头将如下所示:

 extension Dictionary where Value == Set<Double> {

      var explode:[[String:Double]] {
          ....
      }
 }

它不起作用:
关联类型“Element”只能与具体类型或泛型参数基一起使用
。我能理解这一点。但是如何获取元素类型并使用它id输出定义呢

你们很接近。您需要参考
(具体类型参数),而不是
序列
(协议)

这就是说,我很惊讶您的返回值会在这里包含
String
。我希望它能像你的字典一样用同样的方法输入

extension Dictionary where Value: Sequence {

    var explode:[[Key:Value.Element]] {
        ...
    }
}

是的,“字符串”是错误的。非常感谢。
 extension Dictionary where Value:Sequence {

      var explode:[[String:Sequence.Element]] {
          ....
      }
 }
extension Dictionary where Value: Sequence {

    var explode:[[String:Value.Element]] {
        ...
    }
}
extension Dictionary where Value: Sequence {

    var explode:[[Key:Value.Element]] {
        ...
    }
}