Can I extend Tuples in Swift?

As the answer above states, you cannot extend tuples in Swift. However, rather than just give you a no, what you can do is box the tuple inside a class, struct or enum and extend that.

struct TupleStruct {
    var value: (Int, Int)
}
extension TupleStruct : Hashable {
    var hashValue: Int {
        return hash()
    }
    func hash() -> Int {
        var hash = 23
        hash = hash &* 31 &+ value.0
        return hash &* 31 &+ value.1
    }
}

func ==(lhs: TupleStruct, rhs: TupleStruct) -> Bool {
    return lhs.value == rhs.value
}

As a side note, in Swift 2.2, tuples with up to 6 members are now Equatable.


You cannot extend tuple types in Swift. According to Types, there are named types (which can be extended) and compound types. Tuples and functions are compound types.

See also (emphasis added):

Extensions
Extensions add new functionality to an existing class, structure, or enumeration type.