for say I have:
struct S {
var num = 0
}
I wanna implement a function allEqual() as extension for Array<S>
, so I could do thing like
var s1 = S()
var s2 = S()
var s3 = S()
var equality = [s1,s2,s3].allEqual()
for say the specific type is S
extension CollectionType where Generator.Element == S {
}
CollectionType Protocol
In the latest Swift 3.1. You can do same-type constraints on the concrete type extension. So in your case, you can do:
extension Array where Element == S {
func allEqual() -> Bool {
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With