Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend Array constrained when Element is a tuple

Is there a way to extend an Array when the element is a type of tuple ?

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

I can't tell if the errors shown are accurate. Any ideas?

like image 219
the Reverend Avatar asked Dec 18 '15 21:12

the Reverend


2 Answers

Swift 3 version of appzYourLife's answer:

extension Sequence where Iterator.Element == Tuple2 {
    func foo() {}
}
like image 153
Artem Novichkov Avatar answered Nov 10 '22 10:11

Artem Novichkov


It's now possible in Swift 3.1.

extension Array where Element == (String, String) {
    ...
}
like image 35
J.Wang Avatar answered Nov 10 '22 12:11

J.Wang