@Dave, How do I write that though.
I can't write: extension Array: Equatable { static func ==(lhs: Array, rhs: Array) -> Bool { let size = lhs.count precondition(rhs.count == size, "The arrays must be the same length") for i in 0 ..< size { if (lhs[i] as! Equatable) != (rhs[i] as! Equatable) { return false } } return true } } Because I can't cast to an Equatable, because Equatable uses Self. Am I missing something? -- Howard. -- Howard. On 16 November 2016 at 16:35, David Sweeris <daveswee...@mac.com> wrote: > > > On Nov 15, 2016, at 21:39, Howard Lovatt via swift-users < > swift-users@swift.org> wrote: > > > > Hi All, > > > > Does anyone have a good workaround for generics not currently supporting > conditional conformance to a protocol. As stated in the Generics Manifesto > something like this would be nice: > > > > extension Array: Equatable where Element: Equatable { > > static func ==(lhs: Array, rhs: Array) -> Bool { ... } > > } > > > > But I would currently write a wrapper, something like: > > > > struct ArrayE<T: Equatable> { > > var elements: [T] > > } > > extension ArrayE: Equatable { > > static func ==(lhs: ArrayE, rhs: ArrayE) -> Bool { ... } > > } > > > > This can get unwieldy when there are a lot of conditional protocol > extensions required, i.e. wrappers round wrappers. > > > > Is there a better way? > > > > Thanks for any tips, > > > > -- Howard. > > _______________________________________________ > > swift-users mailing list > > swift-users@swift.org > > https://lists.swift.org/mailman/listinfo/swift-users > > Can you make Array conform to Equatable for any T and then in the == > function, if T conforms to Equatable loop the Arrays to check if they're > equal, and if it doesn't conform just return false? > > I mean, it's still "wrong", but at least you won't get any false positives. > > - Dave Sweeris
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users