Using Swift sets with generics

I get compiler errors when I try to define a set of type:

Set<T: Hashable>


The error I get is ('Expected > to complete generic argument list')

I was under the impression that all a set requires of a member is conformance to Hashable. Is there a way to define a generic set? I'm trying to define a method that takes in a set of an arbitrary type T that conforms to hashable, and returns a transformed set of the same type T.

Answered by Jessy in 113398022

What does that mean to you, "generic set"?


struct Struct<Hashable: Swift.Hashable> {
    let set: Set<Hashable>
}


protocol Protocol {
   typealias Hashable: Swift.Hashable
   var set: Set<Hashable> {get}
}
Accepted Answer

What does that mean to you, "generic set"?


struct Struct<Hashable: Swift.Hashable> {
    let set: Set<Hashable>
}


protocol Protocol {
   typealias Hashable: Swift.Hashable
   var set: Set<Hashable> {get}
}
Using Swift sets with generics
 
 
Q