I am using Swift 3.1 and have some generic struct:
struct Section<InfoT: Equatable, ItemsT: Equatable> {
let info: InfoT?
let items: [ItemsT]
}
And want array extension with custom method for elements of this generic type:
extension Array where Element == Section<Equatable, Equatable> {
// Just dummy example function:
func debugDummy() {
for section in self {
let info = section.info
print("section info: \(info).")
for item in section.items {
print("item: \(item).")
}
}
}
}
This gives me compilation errors:
error: using 'Equatable' as a concrete type conforming to protocol 'Equatable' is not supported
extension Array where Element == Section<Equatable, Equatable> {
^
error: GenericsListPlayground.playground:6:24: error: value of type 'Element' has no member 'info'
let info = section.info
^~~~~~~ ~~~~
error: GenericsListPlayground.playground:8:25: error: value of type 'Element' has no member 'items'
for item in section.items {
^~~~~~~ ~~~~~
How to properly declare such extension? I have tried few variations for declaring this extension, like:
extension Array where Element == Section (no arguments)
produces:
error: reference to generic type 'Section' requires arguments in <...>
etc... none of them want to compile.