arrays - 当元素是元组时扩展数组受限

标签 arrays swift generics swift2

当元素是元组类型时,是否有扩展数组的方法?

public extension Array where Element: (timeZoneName: String, formattedName: String){

}

This declaration returns 4 errors:

  • Statement cannot begin with a closure expression
  • Braced block statements is an unused closure
  • Expected '{' in extension
  • Expected identifier for type name

我无法判断显示的错误是否准确。 有什么想法吗?

最佳答案

Swift 3 版本 appzYourLife的回答:

extension Sequence where Iterator.Element == Tuple2 {
    func foo() {}
}

关于arrays - 当元素是元组时扩展数组受限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364344/

相关文章:

javascript - 如何替换数组中的项目?

arrays - Excel VBA : Variants in Array Variables

c++ - std::vector 在加载/清除大量数据时变得越来越慢

swift - PickerView 在文本字段输入中不显示任何内容

ios - 我可以快速将字符串转换为代码块吗?

arrays - 如何找到其值具有最多元素的散列的键

swift - 如何在 Swift 2 Xcode 7 中生成随机数?

scala - 方法定义的类型参数背后的动机

java - 通用构造函数的好处

java - 在递归通用数据结构中对对象进行排序